home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / OpenDoc 1.2b2c1 / TestParts / Draw / DrawPart.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-01  |  191.0 KB  |  6,799 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        DrawPart.cpp
  3.  
  4.     Contains:    Draw test part
  5.  
  6.     Owned by:    SomVersion by Eric House; original by others
  7.  
  8.     Copyright:    © 1994 - 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <5>      10/18/96    DM        1393717: incidental ODFrame property
  13.                                     changes need not dirty draft
  14.          <4>     9/26/96    CC        AttachSourceFrame: newFrame must be
  15.                                     released.
  16.          <3>     5/24/96    jpa        1246074: SOM_CATCH --> SOM_TRY
  17.          <2>    .03.1996    NP        1307182: Added Preferences menu handling
  18.                                     for testing.
  19.  
  20.     To Do:
  21.     In Progress:
  22.  
  23. */
  24.  
  25. #ifndef _ALTPOINT_
  26. #include "AltPoint.h"            // Use C++ savvy ODPoint and ODRect
  27. #endif
  28.  
  29. #ifndef _ODMEMORY_
  30. #include "ODMemory.h"
  31. #endif
  32.  
  33. #define SOM_Module_drawpart_Source
  34. #define VARIABLE_MACROS
  35. #include <DrawPart.xih>
  36.  
  37. #ifndef _DRWSHARED_
  38. #include "DrwShared.h"
  39. #endif
  40.  
  41. #ifndef _PLFMDEF_
  42. #include <PlfmDef.h>
  43. #endif
  44.  
  45. #ifndef _DRAWOBJ_
  46. #include "DrawObj.h"
  47. #endif
  48.  
  49. #ifndef __EVENTS__
  50. #include <Events.h>        // GetMouse, StillDown.
  51. #endif
  52.  
  53. #ifndef __MENUS__
  54. #include <Menus.h>
  55. #endif
  56.  
  57. #ifndef __QUICKDRAW__
  58. #include <Quickdraw.h>
  59. #endif
  60.  
  61. #ifndef __RESOURCES__
  62. #include <Resources.h>
  63. #endif
  64.  
  65. #ifndef __ICONS__
  66. #include <Icons.h>
  67. #endif
  68.  
  69. #ifndef __PICKER__
  70. #include <Picker.h>
  71. #endif
  72.  
  73. #ifndef __TOOLUTILS__
  74. #include <ToolUtils.h>    // HiWord etc.
  75. #endif
  76.  
  77. #ifndef __LIMITS__
  78. #include <limits.h>
  79. #endif
  80.  
  81. #ifndef __STDLIB__
  82. #include <StdLib.h>        // Abs
  83. #endif
  84.  
  85. #ifndef _STDIO
  86. #include <stdio.h>
  87. #endif
  88.  
  89. #ifndef _STRING
  90. #include <string.h>
  91. #endif
  92.  
  93. #ifndef _STDTYPIO_
  94. #include "StdTypIO.h"
  95. #endif
  96.  
  97. #ifndef _USERSRCM_
  98. #include "UseRsrcM.h"
  99. #endif
  100.  
  101. #ifndef _DOCUTILS_
  102. #include <DocUtils.h>
  103. #endif
  104.  
  105. #ifndef SOM_Module_OpenDoc_Foci_defined
  106. #include <Foci.xh>
  107. #endif
  108.  
  109. #ifndef SOM_ODDragItemIterator_xh
  110. #include "DgItmIt.xh"
  111. #endif
  112.  
  113. #ifndef SOM_Module_OpenDoc_Global_Types_defined
  114. #include "ODTypesM.xh"
  115. #endif
  116.  
  117. #ifndef SOM_ODFocusSet_xh
  118. #include <FocusSet.xh>
  119. #endif
  120.  
  121. #ifndef SOM_Module_OpenDoc_Commands_defined
  122. #include <CmdDefs.xh>
  123. #endif
  124.  
  125. #ifndef SOM_ODArbitrator_xh
  126. #include <Arbitrat.xh>
  127. #endif
  128.  
  129. #ifndef SOM_ODInfo_xh
  130. #include <Info.xh>
  131. #endif
  132.  
  133. #ifndef _INFOUTIL_
  134. #include <InfoUtil.h>
  135. #endif
  136.  
  137. #ifndef _ISOSTRING_
  138. #include "ISOStr.h"
  139. #endif
  140.  
  141. #ifndef _ITEXT_
  142. #include <IText.h>
  143. #endif
  144.  
  145. #ifndef __FONTS__
  146. #include <Fonts.h>
  147. #endif
  148.  
  149. #ifndef __SCRIPT__
  150. #include <Script.h>
  151. #endif
  152.  
  153. #ifndef _ORDCOLL_
  154. #include "OrdColl.h"
  155. #endif
  156.  
  157. #ifndef SOM_ODDraft_xh
  158. #include <Draft.xh>
  159. #endif
  160.  
  161. #ifndef SOM_ODDispatcher_xh
  162. #include <Disptch.xh>
  163. #endif
  164.  
  165. #ifndef _EXCEPT_
  166. #include "Except.h"
  167. #endif
  168.  
  169. #ifndef _FOCUSLIB_
  170. #include "FocusLib.h"
  171. #endif
  172.  
  173. #ifndef SOM_ODFacet_xh
  174. #include <Facet.xh>
  175. #endif
  176.  
  177. #ifndef SOM_ODFacetIterator_xh
  178. #include "FacetItr.xh"
  179. #endif
  180.  
  181. #ifndef SOM_ODFrame_xh
  182. #include <Frame.xh>
  183. #endif
  184.  
  185. #ifndef SOM_ODShape_xh
  186. #include <Shape.xh>
  187. #endif
  188.  
  189. #ifndef SOM_ODStorageUnit_xh
  190. #include <StorageU.xh>
  191. #endif
  192.  
  193. #ifndef SOM_Module_OpenDoc_StdProps_defined
  194. #include <StdProps.xh>
  195. #endif
  196.  
  197. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  198. #include <StdTypes.xh>
  199. #endif
  200.  
  201. #ifndef SOM_ODStorageUnitView_xh
  202. #include <SUView.xh>
  203. #endif
  204.  
  205. #ifndef SOM_ODStorageUnitCursor_xh
  206. #include <SUCursor.xh>
  207. #endif
  208.  
  209. #ifndef SOM_ODDraft_xh
  210. #include <Draft.xh>
  211. #endif
  212.  
  213. #ifndef SOM_ODDocument_xh
  214. #include <Document.xh>
  215. #endif
  216.  
  217. #ifndef SOM_ODContainer_xh
  218. #include <ODCtr.xh>
  219. #endif
  220.  
  221. #ifndef SOM_ODSession_xh
  222. #include <ODSessn.xh>
  223. #endif
  224.  
  225. #ifndef SOM_Module_OpenDoc_StandardExtensions_defined
  226. #include <StdExts.xh>
  227. #endif
  228.  
  229. #ifndef SOM_ODMenuBar_xh
  230. #include "MenuBar.xh"
  231. #endif
  232.  
  233. #ifndef SOM_ODWindow_xh
  234. #include <Window.xh>
  235. #endif
  236.  
  237. #ifndef SOM_ODWindowState_xh
  238. #include <WinStat.xh>
  239. #endif
  240.  
  241. #ifndef SOM_ODTransform_xh
  242. #include <Trnsform.xh>
  243. #endif
  244.  
  245. #ifndef SOM_ODFrameFacetIterator_xh
  246. #include "FrFaItr.xh"
  247. #endif
  248.  
  249. #ifndef SOM_DrawSI_xh
  250. #include "DrawSI.xh"
  251. #endif
  252.  
  253. #ifndef _SIHELPER_
  254. #include <SIHelper.h>
  255. #endif
  256.  
  257. #ifndef SOM_ODNameResolver_xh
  258. #include <NamRslvr.xh>
  259. #endif
  260.  
  261. #ifndef _SEUTILS_
  262. #include "SEUtils.h"
  263. #endif
  264.  
  265. #ifndef SOM_Module_OpenDoc_StdProps_defined
  266. #include <StdProps.xh>
  267. #endif
  268.  
  269. #ifndef SOM_ODDragAndDrop_xh
  270. #include <DragDrp.xh>
  271. #endif
  272.  
  273. #ifndef SOM_Module_OpenDoc_StdDefs_defined
  274. #include <StdDefs.xh>
  275. #endif
  276.  
  277. #ifndef SOM_ODCanvas_xh
  278. #include <Canvas.xh>
  279. #endif
  280.  
  281. #ifndef _ODUTILS_
  282. #include <ODUtils.h>
  283. #endif
  284.  
  285. #ifndef _PASCLSTR_
  286. #include "PasclStr.h"
  287. #endif
  288.  
  289. #ifndef SOM_ODUndo_xh
  290. #include <Undo.xh>
  291. #endif
  292.  
  293. #ifndef SOM_ODClipboard_xh
  294. #include <Clipbd.xh>
  295. #endif
  296.  
  297. //#ifndef _DFRMITER_
  298. //#include "DFrmIter.h"
  299. //#endif
  300.  
  301. #ifndef SOM_DrawEmbeddedFramesIterator_xh
  302. #include "DrwEmFrI.xh"
  303. #endif
  304.  
  305. #ifndef __GXMATH__
  306. #include <GXMath.h>
  307. #endif
  308.  
  309. #ifndef __STANDARDFILE__
  310. #include <StandardFile.h>
  311. #endif
  312.  
  313. #ifndef __RESOURCES__
  314. #include <Resources.h>
  315. #endif
  316.  
  317. #ifndef _STORUTIL_
  318. #include <StorUtil.h>
  319. #endif
  320.  
  321. #ifndef _BARRAY_
  322. #include <BArray.h>
  323. #endif
  324.  
  325. #ifndef _WINUTILS_
  326. #include "WinUtils.h"
  327. #endif
  328.  
  329. #ifndef _BNDNSUTL_
  330. #include <BndNSUtl.h>
  331. #endif
  332.  
  333. #ifndef _EDITRSET_
  334. #include <EditrSet.h>
  335. #endif
  336.  
  337. #ifndef _TEMPOBJ_
  338. #include "TempObj.h"
  339. #endif
  340.  
  341. #ifndef _TEMPITER_
  342. #include "TempIter.h"
  343. #endif
  344.  
  345. #ifndef _UTILERRS_
  346. #include "UtilErrs.h"
  347. #endif
  348.  
  349. #ifndef _ODDEBUG_
  350. #include "ODDebug.h"
  351. #endif
  352.  
  353. #pragma segment DrawPart
  354.  
  355. #if ODDebug
  356. #define SCRIPTDEBUG 1
  357. #else
  358. #undef SCRIPTDEBUG
  359. #endif
  360.  
  361. // #define SCRIPTING_OFF
  362.  
  363. static ODSession* gSession;    // For use in Dialog Filter Proc
  364. static Point      gLastPoint;
  365.  
  366. //==============================================================================
  367. // Constants
  368. //==============================================================================
  369.  
  370. #define kNoBias            kODNULL
  371. #define ODDebugCursor    0    // debug cursor location in MouseEnter etc.
  372. #define ODDebugConnections 0 // Facet/Frame added and removed
  373. #define ODDebugActivates 0
  374. #define ODDebugDrags 0
  375.  
  376. #define BETASEEDMODS
  377.  
  378. #define NUKE_PARTSBIN_FOR_DR
  379.  
  380. #define TESTING_DIALOG_TSMTE 1 /* MAKE SURE THIS IS ONLY DEFINED AS 1 or 0 */
  381.  
  382.     const ODSShort kXMPBorderWidth = 5;
  383.     const ODSShort kODHandleLenMultiplier = 3;
  384.  
  385.     static const RGBColor rgbGray =    { 0x7FFF, 0x7FFF, 0x7FFF };
  386.     static const RGBColor rgbRed =        { 0xBFFF, 0x7FFF, 0x7FFF };
  387.     static const RGBColor rgbGreen =    { 0x7FFF, 0xBFFF, 0x7FFF };
  388.     static const RGBColor rgbYellow =    { 0xBFFF, 0xBFFF, 0x7FFF };
  389.     static const RGBColor rgbBlue =    { 0x7FFF, 0x7FFF, 0xBFFF };
  390.     static const RGBColor rgbMagenta =    { 0xBFFF, 0x7FFF, 0xBFFF };
  391.     static const RGBColor rgbCyan =    { 0x7FFF, 0xBFFF, 0xBFFF };
  392.     static const RGBColor rgbWhite =    { 0xFFFF, 0xFFFF, 0xFFFF };
  393.     static const RGBColor rgbBlack =    { 0x0000, 0x0000, 0x0000 };
  394.  
  395.     const ODSShort kPaletteLeft = 0;
  396.     const ODSShort kPaletteRight = 50;
  397.     const ODSShort kPaletteTop = 0;
  398.     const ODSShort kPaletteBottom = 200;
  399.  
  400.     enum {
  401.         kGray = 0,
  402.         kRed,
  403.         kGreen,
  404.         kYellow,
  405.         kBlue,
  406.         kMagenta,
  407.         kCyan,
  408.         kWhite,
  409.         kOther,
  410.         kNumColors = kOther
  411.     };
  412.  
  413.  
  414.     const        ODSShort    kMargin = 10;
  415.  
  416. const short     kSuspendResumeMessage = 0x01;    // Resume vs. suspend mask
  417. const short     kMouseMovedMessage    = 0xFA;    // High byte mouse-moved event message
  418.  
  419. const ODMenuID    kDrawColorMenuID = 4;
  420. const ODMenuID    kDrawEmbedMenuID = 5;
  421. const ODMenuID    kDrawFrameMenuID = 6;
  422.  
  423. //for SCRIPTDEBUG
  424. const ODMenuID    kDrawScriptingMenuID = 7;
  425.  
  426. // $$$$$ EMBED MENU CRUFT.  SHOULD NOT BE HARDCODING OTHER PART KINDS INTO CODE.
  427. static const ODType kODPartTogglePart        = "TogglePart";
  428. static const ODType kODPartButtonPart        = "ButtonPart";
  429. static const ODType kODPartTextPart          = "TextPart";
  430. static const ODType kODPartDrawPart          = "+//ISO 9070/ANSI::113722::US::CI LABS::Apple:Kind:TestDraw";
  431. static const ODType kODPartMoviePart         = "MoviePart";
  432. static const ODType kODPartClockPart         = "+//ISO 9070/ANSI::113722::US::CI LABS::Apple:Kind:TestClock";
  433. static const ODType kODPartStylPart          = "StylPart";
  434. static const ODType kODPartTestPart          = "TestPart";
  435. static const ODType kODPartDragPart          = "+//ISO 9070/ANSI::113722::US::CI LABS::Apple:Kind:TestDrag";
  436. #ifndef NUKE_PARTSBIN_FOR_DR
  437. static const ODType kODPartPartsBin          = "Apple:Kind:PartsBin";
  438.  
  439. static const ODPropertyName kODPropPartsBin     = "Apple:Property:PartsBin";
  440. #endif
  441.  
  442. static const ODPropertyName kODPropEmbeddedFrames     = "+//ISO 9070/ANSI::113722::US::CI LABS::Apple:TestDraw:Property:EmbeddedFrames";
  443. static const ODPropertyName kODPropPrintingInfo     = "+//ISO 9070/ANSI::113722::US::CI LABS::Apple:TestDraw:Property:PrintingInfo";
  444. static const ODPropertyName kPropScriptingOn = "+//ISO 9070/ANSI::113722::US::CI LABS::Apple:TestDraw:Property:ScriptingOn";
  445. static const ODPropertyName kODPropExternalTransform    = "+//ISO 9070/ANSI::113722::US::CI LABS::OpenDoc:Property:ExternalTransform";
  446.  
  447. //==============================================================================
  448. // Commands
  449. //==============================================================================
  450.     
  451.     const ODCommandID cGray = 20001;
  452.     const ODCommandID cRed = 20002;
  453.     const ODCommandID cGreen = 20003;
  454.     const ODCommandID cYellow = 20004;
  455.     const ODCommandID cBlue = 20005;
  456.     const ODCommandID cMagenta = 20006;
  457.     const ODCommandID cCyan = 20007;
  458.     const ODCommandID cWhite = 20008;
  459.     const ODCommandID cOtherColor = 20009;
  460.  
  461. #if TESTING_DIALOG_TSMTE
  462.     const ODCommandID  kODBringUpTestTSMTEDialog   = 20016;
  463. #endif
  464.  
  465. #ifndef NUKE_PARTSBIN_FOR_DR
  466.     const ODCommandID  kODCommandShowPartsBin   = 20012;
  467. #endif
  468.  
  469. #ifdef SCRIPTDEBUG
  470.     const ODCommandID cToggleScripting = 20015;
  471. #endif
  472.  
  473.  
  474. //==============================================================================
  475. // 'ternalization 
  476. //==============================================================================
  477.  
  478.     static const ODPropertyName    kPropFrameInfo = "+//ISO 9070/ANSI::113722::US::CI LABS::Apple:TestDraw:Property:FrameInfo";
  479.  
  480.     static const ODValueType        kQDPoint = "+//ISO 9070/ANSI::113722::US::CI LABS::Apple:TestDraw:Type:Point";
  481.     static const ODValueType        kTPrintRec = "+//ISO 9070/ANSI::113722::US::CI LABS::MacOS:Type:TPrint Record";
  482.     static const ODValueType        kDrawFrameID = "+//ISO 9070/ANSI::113722::US::CI LABS::MacOS:Type:FrameID";
  483.  
  484.     static const ODType            kDrawPresNormal =  "+//ISO 9070/ANSI::113722::US::CI LABS::Apple:TestDraw:Presentation:Normal";
  485.     static const ODType            kDrawPresPalette = "+//ISO 9070/ANSI::113722::US::CI LABS::Apple:TestDraw:Presentation:Palette";
  486.  
  487. #define kKindTestDraw "+//ISO 9070/ANSI::113722::US::CI LABS::Apple:Kind:TestDraw"
  488.  
  489. //==============================================================================
  490. // Function Prototype
  491. //==============================================================================
  492.  
  493. pascal Boolean AboutDialogFilter(DialogPtr dialog,
  494.                               EventRecord* event,
  495.                               short* itemHit);
  496.  
  497. ODBoolean RGBEqual(RGBColor a,RGBColor b);    // Function Prototype for correctness
  498.  
  499. ODBoolean RGBEqual(RGBColor a,RGBColor b)
  500. {
  501.     return (a.red == b.red &&
  502.             a.green == b.green &&
  503.             a.blue == b.blue);
  504. }
  505.  
  506. ODUShort DetermineNumberOfPagesinDoc(Environment* ev, ODFrame* frame, Rect page);
  507. ODBoolean ValueOnClipboard(Environment* ev, ODSession* session);
  508.  
  509. static void ShowMyDragHilite(Environment* ev, ODDragAndDrop* dad, ODFacet* facet);
  510. static void HideMyDragHilite(Environment* ev, ODDragAndDrop* dad, ODFacet* facet);
  511. static void CommonInvertFacet(Environment* ev, ODDragAndDrop* dad, ODFacet* facet, boolean show);
  512.  
  513. //==============================================================================
  514. // Global Variable
  515. //==============================================================================
  516.  
  517. static Proxy*    dadSelection;
  518. static ODFacet*    gDragHilitedFacet = kODNULL;
  519.  
  520. //==============================================================================
  521. // Finally, the code....
  522. //==============================================================================
  523.  
  524. //------------------------------------------------------------------------------
  525. // DrawPart::GetSemanticInterface
  526. //------------------------------------------------------------------------------
  527.  
  528. SOM_Scope DrawSI*  SOMLINK AppleTest_ContainerGetSemanticInterface(AppleTest_Container *somSelf, Environment *ev)
  529. {
  530.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  531.     AppleTest_ContainerMethodDebug("AppleTest_Container","GetSemanticInterface");
  532.     
  533.     SOM_TRY
  534.  
  535. #ifndef SCRIPTING_OFF
  536.     return _fSemtIntf;
  537. #else
  538.     return kODNULL;
  539. #endif
  540.  
  541.     SOM_CATCH_ALL_ENDTRY
  542.     return kODNULL;
  543. }
  544.  
  545. // $$$$$ a very temporary hack....
  546. static short ItemFromClass(DescType theClass)
  547. {
  548.     short item;
  549.     
  550.     switch(theClass)
  551.     {
  552.         case cDrawPart : item = 1;
  553.         case cDragPart : item = 2;
  554.         case cClockPart : item = 3;
  555.         case cTestPart : item = 4;
  556.     }
  557.     
  558.     return item;
  559. }
  560.  
  561. //------------------------------------------------------------------------------
  562. // DrawPart::CreateNewPart
  563. //------------------------------------------------------------------------------
  564.  
  565. SOM_Scope ODPart*  SOMLINK AppleTest_ContainerCreateNewPart(AppleTest_Container *somSelf, Environment *ev,
  566.         DescType theClass,
  567.         AEDesc* theLocation)
  568. {
  569.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  570.     AppleTest_ContainerMethodDebug("AppleTest_Container","CreateNewPart");
  571.     
  572.     SOM_TRY
  573.  
  574.     ODUnused(theLocation);
  575.     OrderedCollectionIterator iter(_fDisplayFrames);
  576.     ODFrame* frame = (ODFrame*)iter.First();
  577.  
  578.     ODPart* theResult;
  579.     somSelf->Embed(ev, ItemFromClass(theClass), frame, &theResult);
  580.     return theResult;
  581.  
  582.     SOM_CATCH_ALL_ENDTRY
  583.     return kODNULL;
  584. }
  585.  
  586. //------------------------------------------------------------------------------
  587. // DrawPart::SetNewBounds
  588. //------------------------------------------------------------------------------
  589.  
  590. SOM_Scope void  SOMLINK AppleTest_ContainerSetNewBounds(AppleTest_Container *somSelf, Environment *ev,
  591.         ODFrame* frame,
  592.         Rect* r)
  593. {
  594.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  595.     AppleTest_ContainerMethodDebug("AppleTest_Container","SetNewBounds");
  596.  
  597.     SOM_TRY
  598.  
  599.     Proxy* p = somSelf->ProxyForFrame(ev, frame);
  600.  
  601.     Point pt = *(Point*)r;
  602.     p->transform->SetQDOffset(ev, &pt);
  603.  
  604.     Rect rNormalized = *r;
  605.     OffsetRect(&rNormalized, -pt.h, -pt.v);
  606.     ODRect xmpr = rNormalized;
  607.     TempODShape shape = frame->AcquireFrameShape(ev, kODNULL);
  608.     shape->SetRectangle(ev, &xmpr);
  609.     
  610.     ODFrameFacetIterator* fi = frame->CreateFacetIterator(ev);
  611.     for(ODFacet* facet = fi->First(ev); fi->IsNotComplete(ev);
  612.             facet = fi->Next(ev))
  613.     {
  614.         TempODTransform newXform = p->transform->Copy(ev);
  615.         facet->ChangeGeometry(ev, kODNULL, newXform, kODNULL);
  616.         facet->Invalidate(ev, kODNULL, kODNULL);
  617.     }
  618.     delete fi;
  619.  
  620.     frame->ChangeFrameShape(ev, shape, kODNULL);
  621.  
  622.     SOM_CATCH_ALL_ENDTRY
  623. }
  624.  
  625. //------------------------------------------------------------------------------
  626. // DrawPart: CreateFrameProxy
  627. //------------------------------------------------------------------------------
  628.  
  629. SOM_Scope void  SOMLINK AppleTest_ContainerCreateFrameProxy(AppleTest_Container *somSelf, Environment *ev,
  630.         ODFrame* frame,
  631.         ODTransform* externalTransform)
  632. {
  633.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  634.     AppleTest_ContainerMethodDebug("AppleTest_Container","CreateFrameProxy");
  635.  
  636.     SOM_TRY
  637.     
  638.     // add the frame to the collection of embedded frames
  639.     frame->Acquire(ev); // DMc bump ref: going into collection
  640.     _fEmbeddedFrames->AddFirst(frame);
  641.  
  642.     // calculate the frame shape's region
  643.     ODShape* shape = frame->AcquireFrameShape(ev, kODNULL);
  644.     ODShape* shapeCopy = shape->Copy(ev);
  645.     
  646.     shapeCopy->Transform(ev, externalTransform);
  647.     RgnHandle shapeRgn = shapeCopy->CopyQDRegion(ev);
  648.     
  649.     shapeCopy->Release(ev); shapeCopy = kODNULL;
  650.     shape->Release(ev); shape = kODNULL;
  651.     
  652.     // create a proxy to hold the embedded frame
  653.     externalTransform->Acquire(ev); // DMc bump ref: going into structure
  654.     Proxy* p = new Proxy(shapeRgn, frame, externalTransform);  // new for Facets
  655.  
  656.     // put proxy into contents, possibly adjusting other content
  657.     _fContents->AddFirst(p);
  658.  
  659.     SOM_CATCH_ALL_ENDTRY
  660. }
  661.  
  662. //------------------------------------------------------------------------------
  663. // DrawPart: DeleteFrameProxy
  664. //------------------------------------------------------------------------------
  665.  
  666. SOM_Scope void  SOMLINK AppleTest_ContainerDeleteFrameProxy(AppleTest_Container *somSelf, Environment *ev,
  667.         Proxy* proxy)
  668. {
  669.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  670.     AppleTest_ContainerMethodDebug("AppleTest_Container","DeleteFrameProxy");
  671.  
  672.     SOM_TRY
  673.     
  674.     if ( proxy )
  675.     {    
  676.         if ( _fEmbeddedFrames->Contains(proxy->frame) )
  677.         {
  678.             _fEmbeddedFrames->Remove(proxy->frame);
  679.             ODReleaseObject(ev, proxy->frame);
  680.         }
  681.  
  682.         _fContents->Remove(proxy);
  683.         
  684.         proxy->transform->Release(ev); proxy->transform = kODNULL; // DMc - transform is a field
  685.         ODDisposeHandle((Handle)proxy->region);
  686.         delete proxy;
  687.     }
  688.  
  689.     SOM_CATCH_ALL_ENDTRY
  690. }
  691.  
  692. //------------------------------------------------------------------------------
  693. // DrawPart: ProxyForFrame
  694. //------------------------------------------------------------------------------
  695.  
  696. SOM_Scope Proxy*  SOMLINK AppleTest_ContainerProxyForFrame(AppleTest_Container *somSelf, Environment *ev,
  697.         ODFrame* frame)
  698. {
  699.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  700.     AppleTest_ContainerMethodDebug("AppleTest_Container","ProxyForFrame");
  701.  
  702.     SOM_TRY
  703.     
  704.     Proxy* rp = kODNULL;
  705.     
  706.     if (_fEmbeddedFrames->Contains(frame))
  707.     {
  708.         OrderedCollectionIterator i(_fContents);
  709.         Proxy* p;
  710.         for (p = (Proxy*) i.First(); i.IsNotComplete(); p = (Proxy*) i.Next())
  711.         {
  712.             if (p->frame == frame)
  713.                 rp = p;
  714.         }
  715.     }
  716.     if (!rp)
  717.         THROW(kODErrInvalidFrame);
  718.  
  719.     return rp;
  720.  
  721.     SOM_CATCH_ALL_ENDTRY
  722.     return kODNULL;
  723. }
  724.  
  725.  
  726. /*
  727.  * SOM_Scope void  SOMLINK AppleTest_ContainerUpdateProxyRegion(AppleTest_Container *somSelf, Environment *ev,
  728.  *         Proxy proxy)
  729.  */
  730.  
  731. /*
  732.  * The prototype for AppleTest_ContainerUpdateProxyRegion was replaced by the following prototype:
  733.  */
  734. SOM_Scope void  SOMLINK AppleTest_ContainerUpdateProxyRegion(AppleTest_Container *somSelf, Environment *ev,
  735.         Proxy* proxy)
  736. {
  737.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  738.     AppleTest_ContainerMethodDebug("AppleTest_Container","UpdateProxyRegion");
  739.  
  740.     SOM_TRY
  741.     
  742.     TempODShape scratch = ODCopyAndRelease(ev, proxy->frame->AcquireFrameShape(ev, kODNULL));
  743.     scratch->Transform(ev, proxy->transform);
  744.     RgnHandle scratchRgn = scratch->GetQDRegion(ev);
  745.     CopyRgn(scratchRgn, proxy->region);
  746.  
  747.     SOM_CATCH_ALL_ENDTRY
  748. }
  749.  
  750. SOM_Scope void  SOMLINK AppleTest_ContainerCreateProxySelectionBorder(AppleTest_Container *somSelf, Environment *ev,
  751.         Proxy* p)
  752. {
  753.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  754.     AppleTest_ContainerMethodDebug("AppleTest_Container","CreateProxySelectionBorder");
  755.  
  756.     SOM_TRY
  757.     
  758.     // -- selection border region --
  759.  
  760.     ODRgnHandle border = ODNewRgn();
  761.     CopyRgn(p->region, border);
  762.     InsetRgn(border, -1, -1);
  763.     DiffRgn(border, p->region, border);
  764.  
  765.     Rect borderRect = (**border).rgnBBox;
  766.     Rect tempRect;
  767.     
  768.     // -- corner region --
  769.  
  770.     RgnHandle cornerHdlRgn = ODNewRgn();
  771.     OpenRgn();
  772.     PenSize(1,1);
  773.     
  774.     // top left handle
  775.     SetRect(&tempRect, borderRect.left-2, borderRect.top-2,
  776.                        borderRect.left+3, borderRect.top+3);
  777.     FrameRect(&tempRect);
  778.     
  779.     // top right handle
  780.     SetRect(&tempRect, borderRect.right-3, borderRect.top-2,
  781.                        borderRect.right+2, borderRect.top+3);
  782.     FrameRect(&tempRect);
  783.  
  784.     // bottom left handle
  785.     SetRect(&tempRect, borderRect.left-2, borderRect.bottom-3,
  786.                        borderRect.left+3, borderRect.bottom+2);
  787.     FrameRect(&tempRect);
  788.  
  789.     // bottom right handle
  790.     SetRect(&tempRect, borderRect.right-3, borderRect.bottom-3,
  791.                        borderRect.right+2, borderRect.bottom+2);
  792.     FrameRect(&tempRect);
  793.  
  794.     CloseRgn(cornerHdlRgn);
  795.  
  796.     // -- edge region --
  797.  
  798.     RgnHandle edgeHdlRgn = ODNewRgn();
  799.     OpenRgn();
  800.  
  801.     if ((borderRect.right - borderRect.left) >= 12) {
  802.     
  803.         short hcenter = (borderRect.right + borderRect.left) / 2;
  804.         
  805.         // top middle handle
  806.         SetRect(&tempRect, hcenter-2, borderRect.top-2,
  807.                            hcenter+3, borderRect.top+3);
  808.         FrameRect(&tempRect);
  809.  
  810.         // bottom middle handle
  811.         SetRect(&tempRect, hcenter-2, borderRect.bottom-3,
  812.                            hcenter+3, borderRect.bottom+2);
  813.         FrameRect(&tempRect);
  814.     }
  815.     
  816.     if ((borderRect.bottom - borderRect.top) >= 12) {
  817.     
  818.         short vcenter = (borderRect.bottom + borderRect.top) / 2;
  819.         
  820.         // left middle handle
  821.         SetRect(&tempRect, borderRect.left-2, vcenter-2,
  822.                            borderRect.left+3, vcenter+3);
  823.         FrameRect(&tempRect);
  824.         
  825.         // right middle handle
  826.         SetRect(&tempRect, borderRect.right-3, vcenter-2,
  827.                            borderRect.right+2, vcenter+3);
  828.         FrameRect(&tempRect);
  829.     }
  830.     
  831.     CloseRgn(edgeHdlRgn);
  832.  
  833.     // clip by obscuring frames
  834.  
  835.     Proxy* q;
  836.     OrderedCollectionIterator i(_fContents);
  837.     ODBoolean above = true;
  838.     for (q = (Proxy*) i.First(); i.IsNotComplete(); q = (Proxy*) i.Next())
  839.     {    if (p == q) {above = false; continue;}
  840.         if (!above) {continue;}
  841.         DiffRgn(border, q->region, border);
  842.         DiffRgn(cornerHdlRgn, q->region, cornerHdlRgn);
  843.         DiffRgn(edgeHdlRgn, q->region, edgeHdlRgn);
  844.     };
  845.  
  846.  
  847.     if ( _fCornerHandleRgn ) ODDisposeHandle((Handle)_fCornerHandleRgn);
  848.     _fCornerHandleRgn = cornerHdlRgn;
  849.     UnionRgn(border, cornerHdlRgn, border);
  850.  
  851.     if ( _fEdgeHandleRgn ) ODDisposeHandle((Handle)_fEdgeHandleRgn);
  852.     _fEdgeHandleRgn = edgeHdlRgn;
  853.     UnionRgn(border, edgeHdlRgn, border);
  854.     
  855.     if ( _fSelectRgn ) ODDisposeHandle((Handle)_fSelectRgn);
  856.     _fSelectRgn = border;
  857.  
  858.     SOM_CATCH_ALL_ENDTRY
  859. }
  860.  
  861. SOM_Scope void  SOMLINK AppleTest_ContainerInvalidateSelection(AppleTest_Container *somSelf, Environment *ev,
  862.         ODFrame* frame)
  863. {
  864.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  865.     AppleTest_ContainerMethodDebug("AppleTest_Container","InvalidateSelection");
  866.  
  867.     SOM_TRY
  868.     
  869.     if ( _fSelectRgn )
  870.     {
  871.         ODShape* selectShape = frame->CreateShape(ev);
  872.         UnionRgn(_fSelectRgn,_fCornerHandleRgn,_fSelectRgn);
  873.         selectShape->SetQDRegion(ev, (RgnHandle)ODCopyHandle((ODHandle)_fSelectRgn));
  874.         frame->Invalidate(ev, selectShape, kODNULL);
  875.         selectShape ->Release(ev);
  876.     }
  877.  
  878.     SOM_CATCH_ALL_ENDTRY
  879. }
  880.  
  881. SOM_Scope void  SOMLINK AppleTest_ContainerClipEmbeddedFrames(AppleTest_Container *somSelf, Environment *ev,
  882.         ODFrame* frame)
  883. {
  884.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  885.     AppleTest_ContainerMethodDebug("AppleTest_Container","ClipEmbeddedFrames");
  886.  
  887.     SOM_TRY
  888.     
  889.     ODFrameFacetIterator* facets = frame->CreateFacetIterator(ev);
  890.     for (ODFacet* facet = facets->First(ev); facets->IsNotComplete(ev);
  891.             facet = facets->Next(ev))
  892.         somSelf->ClipEmbeddedFacets(ev, facet);
  893.     delete facets;
  894.  
  895.     SOM_CATCH_ALL_ENDTRY
  896. }
  897.  
  898. SOM_Scope void  SOMLINK AppleTest_ContainerCommonInitContainerPart(AppleTest_Container *somSelf, Environment *ev)
  899. {
  900.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  901.     AppleTest_ContainerMethodDebug("AppleTest_Container","CommonInitDrawPart");
  902.  
  903.     SOM_TRY
  904.     
  905.     _fDisplayFrames = new OrderedCollection;
  906.     _fEmbeddedFrames = new OrderedCollection;
  907.  
  908.     RGBColor random;
  909.     random.red = Random();
  910.     random.green = Random();
  911.     random.blue = Random();
  912.     _fDefaultColor = random;
  913.  
  914.     _fContents = new OrderedCollection;
  915.     _fSelection = new OrderedCollection;
  916.     
  917.     _fSelectRgn = ODNewRgn();
  918.     _fCornerHandleRgn = ODNewRgn();
  919.     _fEdgeHandleRgn = ODNewRgn();
  920.  
  921.     _fColorMenu = NewMenu(kDrawColorMenuID,"\pBackground");
  922.     _fEmbedMenu = NewMenu(kDrawEmbedMenuID,"\pArrange");
  923. #ifndef BETASEEDMODS
  924.     _fFrameMenu = NewMenu(kDrawFrameMenuID,"\pFrame");
  925. #endif
  926.  
  927. #ifndef BETASEEDMODS
  928.     if (!_fColorMenu  || !_fFrameMenu)
  929. #else
  930.     if ( !_fColorMenu || !_fEmbedMenu)
  931. #endif
  932.         WARN("Error creating menus");
  933.     
  934. #ifdef SCRIPTDEBUG
  935.     _fScriptingMenu = NewMenu(kDrawScriptingMenuID,"\pScripting");
  936.     if (!_fScriptingMenu) WARN("Error creating scripting menu");
  937. #endif
  938.     
  939.     _fSession = somSelf->/*ODPersistentObject::*/GetStorageUnit(ev)->GetSession(ev);
  940.     gSession = _fSession;
  941.  
  942.     AppendMenu(_fColorMenu,"\pGray");
  943.     AppendMenu(_fColorMenu,"\pRed");
  944.     AppendMenu(_fColorMenu,"\pGreen");
  945.     AppendMenu(_fColorMenu,"\pYellow");
  946.     AppendMenu(_fColorMenu,"\pBlue");
  947.     AppendMenu(_fColorMenu,"\pMagenta");
  948.     AppendMenu(_fColorMenu,"\pCyan");
  949.     AppendMenu(_fColorMenu,"\pWhite");
  950.     AppendMenu(_fColorMenu,"\pOther…");
  951.  
  952.     AppendMenu(_fEmbedMenu,"\pNon-Standard Insert…");
  953. #if TESTING_DIALOG_TSMTE
  954.     AppendMenu(_fEmbedMenu,"\pBring up TSMTE Test Dialog…");
  955. #endif
  956. #ifndef NUKE_PARTSBIN_FOR_DR
  957.     AppendMenu(_fEmbedMenu,"\pShow Parts Bin");
  958. #endif
  959.     
  960. #ifndef BETASEEDMODS
  961.     AppendMenu(_fEmbedMenu,"\pDrag Text");
  962.     AppendMenu(_fEmbedMenu,"\pTime");
  963.     
  964.     AppendMenu(_fFrameMenu,"\pFreeze");
  965.     AppendMenu(_fFrameMenu,"\pDefrost");
  966. #endif
  967.  
  968. #ifdef SCRIPTDEBUG
  969.     if (_fScriptingOn) AppendMenu(_fScriptingMenu,"\pTurn Scripting Off");
  970.     else AppendMenu(_fScriptingMenu,"\pTurn Scripting On");
  971. #endif
  972.  
  973.     _fMenuBar = _fSession->GetWindowState(ev)->CopyBaseMenuBar(ev);
  974.  
  975.     _fMenuBar->AddMenuLast(ev, kDrawEmbedMenuID, _fEmbedMenu, _fPartWrapper);
  976.     _fMenuBar->AddMenuLast(ev, kDrawColorMenuID, _fColorMenu, _fPartWrapper);
  977. #ifndef BETASEEDMODS
  978.     _fMenuBar->AddMenuLast(ev, kDrawFrameMenuID, _fFrameMenu, _fPartWrapper);
  979. #endif
  980.     
  981. #ifdef SCRIPTDEBUG
  982.     _fMenuBar->AddMenuLast(ev, kDrawScriptingMenuID, _fScriptingMenu, _fPartWrapper);
  983. #endif
  984.     
  985.     _fMenuBar->RegisterCommand(ev, cGray, kDrawColorMenuID, 1);
  986.     _fMenuBar->RegisterCommand(ev, cRed, kDrawColorMenuID, 2);
  987.     _fMenuBar->RegisterCommand(ev, cGreen, kDrawColorMenuID, 3);
  988.     _fMenuBar->RegisterCommand(ev, cYellow, kDrawColorMenuID, 4);
  989.     _fMenuBar->RegisterCommand(ev, cBlue, kDrawColorMenuID, 5);
  990.     _fMenuBar->RegisterCommand(ev, cMagenta, kDrawColorMenuID, 6);
  991.     _fMenuBar->RegisterCommand(ev, cCyan, kDrawColorMenuID, 7);
  992.     _fMenuBar->RegisterCommand(ev, cWhite, kDrawColorMenuID, 8);
  993.     _fMenuBar->RegisterCommand(ev, cOtherColor, kDrawColorMenuID, 9);
  994.         
  995. #if TESTING_DIALOG_TSMTE
  996.     _fMenuBar->RegisterCommand(ev, kODBringUpTestTSMTEDialog, kDrawEmbedMenuID, 2);
  997. #endif
  998. #ifndef NUKE_PARTSBIN_FOR_DR
  999.     // DEPENDS ON THE POSITION OF THE TESTING_DIALOG_TSMTE MENU ITEM
  1000.     _fMenuBar->RegisterCommand(ev, kODCommandShowPartsBin, kDrawEmbedMenuID,
  1001.                                 2 + TESTING_DIALOG_TSMTE);
  1002. #endif
  1003.         
  1004. #ifdef SCRIPTDEBUG
  1005.     _fMenuBar->RegisterCommand(ev, cToggleScripting, kDrawScriptingMenuID, 1);
  1006. #endif
  1007.         
  1008.     _fSelectionFocus = _fSession->Tokenize(ev, kODSelectionFocus);
  1009.     _fMenuFocus = _fSession->Tokenize(ev, kODMenuFocus);
  1010.     _fKeyFocus = _fSession->Tokenize(ev, kODKeyFocus);
  1011.     _fClipboardFocus = _fSession->Tokenize(ev, kODClipboardFocus);
  1012.  
  1013. #if 1
  1014.     // The way it should be
  1015.     _fFocusSet = _fSession->GetArbitrator(ev)->CreateFocusSet(ev);
  1016. #else
  1017.     // The way it has to be until Richard implements the above:
  1018.     _fFocusSet = new ODFocusSet; _fFocusSet->InitFocusSet(ev);
  1019. #endif
  1020.     _fFocusSet->Add(ev, _fSelectionFocus);
  1021.     _fFocusSet->Add(ev, _fMenuFocus);
  1022.     _fFocusSet->Add(ev, _fKeyFocus);
  1023.     
  1024. #ifndef SCRIPTING_OFF
  1025.     _fSemtIntf = new DrawSI;
  1026.     SIHelper* semItfcHelper = new SIHelper;
  1027.     semItfcHelper->InitSIHelper(_fSession, _fSemtIntf);
  1028.     _fSemtIntf->InitCPlusSemanticInterface(ev, somSelf, semItfcHelper, _fSession);
  1029.  
  1030.     somSelf->InstallObjectAccessors(ev);
  1031. #endif
  1032.     
  1033.     ODQDGlobals.randSeed = TickCount();
  1034.     
  1035.     somSelf->LoadIcons(ev);
  1036.  
  1037.     SOM_CATCH_ALL_ENDTRY
  1038. }
  1039.  
  1040. SOM_Scope void  SOMLINK AppleTest_ContainerLoadIcons(AppleTest_Container *somSelf, Environment *ev)
  1041. {
  1042.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  1043.     AppleTest_ContainerMethodDebug("AppleTest_Container","LoadIcons");
  1044.  
  1045.     SOM_TRY
  1046.     
  1047.     ODSLong        savedRefNum;
  1048.     BeginUsingLibraryResources(savedRefNum);
  1049.  
  1050.     Handle largesuite;
  1051.     OSErr osr = NewIconSuite(&largesuite);
  1052.     THROW_IF_ERROR(osr,"Error creating icon suite");
  1053.     
  1054.     Handle icon = GetResource('icl8',90);
  1055.     THROW_IF_ERROR(ResError(),"Trouble loading icons (icl8)");
  1056.     DetachResource(icon);
  1057.     osr = AddIconToSuite(icon,largesuite,'icl8');
  1058.     
  1059.     icon = GetResource('icl4',90);
  1060.     THROW_IF_ERROR(ResError(),"Trouble loading icons (icl4)");
  1061.     DetachResource(icon);
  1062.     osr = AddIconToSuite(icon,largesuite,'icl4');
  1063.     
  1064.     icon = GetResource('ICN#',90);
  1065.     THROW_IF_ERROR(ResError(),"Trouble loading icons (ICN#)");
  1066.     DetachResource(icon);
  1067.     osr = AddIconToSuite(icon,largesuite,'ICN#');
  1068.  
  1069.     if (largesuite) _fLargeIcons = largesuite;
  1070.  
  1071.     Handle smallsuite;
  1072.     osr = NewIconSuite(&smallsuite);
  1073.     THROW_IF_ERROR(osr,"Error creating icon suite");
  1074.     
  1075.     icon = GetResource('ics8',90);
  1076.     THROW_IF_ERROR(ResError(),"Trouble loading icons (ics8)");
  1077.     DetachResource(icon);
  1078.     osr = AddIconToSuite(icon,smallsuite,'ics8');
  1079.     
  1080.     icon = GetResource('ics4',90);
  1081.     THROW_IF_ERROR(ResError(),"Trouble loading icons (ics4)");
  1082.     DetachResource(icon);
  1083.     osr = AddIconToSuite(icon,smallsuite,'ics4');
  1084.     
  1085.     icon = GetResource('ics#',90);
  1086.     THROW_IF_ERROR(ResError(),"Trouble loading icons (ics#)");
  1087.     DetachResource(icon);
  1088.     osr = AddIconToSuite(icon,smallsuite,'ics#');
  1089.  
  1090.     if (smallsuite) _fSmallIcons = smallsuite;
  1091.     
  1092.     EndUsingLibraryResources(savedRefNum);
  1093.  
  1094.     SOM_CATCH_ALL_ENDTRY
  1095. }
  1096.  
  1097. SOM_Scope void  SOMLINK AppleTest_ContainerRelease(AppleTest_Container *somSelf, Environment *ev)
  1098. {
  1099.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  1100.     AppleTest_ContainerMethodDebug("AppleTest_Container","Release");
  1101.  
  1102.     SOM_TRY
  1103.     
  1104.     parent_Release(somSelf, ev);
  1105.     if (somSelf->GetRefCount(ev) == 0)
  1106.         somSelf->GetStorageUnit(ev)->GetDraft(ev)->ReleasePart(ev, _fPartWrapper);
  1107.  
  1108.     SOM_CATCH_ALL_ENDTRY
  1109. }
  1110.  
  1111. SOM_Scope void  SOMLINK AppleTest_ContainerReleaseAll( AppleTest_Container *somSelf,
  1112.                                                         Environment *ev )
  1113. {
  1114.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  1115.     AppleTest_ContainerMethodDebug("AppleTest_Container","ReleaseAll");
  1116.  
  1117.     SOM_TRY
  1118.     
  1119. #ifndef SCRIPTING_OFF
  1120.     if (_fSemtIntf != kODNULL)    
  1121.     {
  1122.         delete ((SIHelper*)_fSemtIntf->GetSIHelper(ev));
  1123.         ODFinalReleaseObject(ev, _fSemtIntf);
  1124.     }
  1125. #endif
  1126.  
  1127.     Proxy*        p;
  1128.     ODFrame*    frame;
  1129.     
  1130.     somSelf->HidePalette(ev);
  1131.     frame = (ODFrame*) _fDisplayFrames->First();
  1132.     while (frame != kODNULL) {
  1133.         _fDisplayFrames->Remove(frame);
  1134.         ODReleaseObject(ev,frame);
  1135.         frame = (ODFrame*) _fDisplayFrames->First();
  1136.     }
  1137.     frame = (ODFrame*) _fEmbeddedFrames->First();
  1138.     while (frame != kODNULL) {
  1139.         p = somSelf->ProxyForFrame(ev, frame);
  1140.         _fContents->Remove(p);
  1141.         _fEmbeddedFrames->Remove(frame);
  1142.         ODReleaseObject(ev,frame);
  1143.         frame = (ODFrame*) _fEmbeddedFrames->First();
  1144.     }
  1145.  
  1146.     SOM_CATCH_ALL_ENDTRY
  1147. }
  1148.  
  1149. SOM_Scope void  SOMLINK AppleTest_ContainerInstallObjectAccessors(AppleTest_Container *somSelf, Environment *ev)
  1150. {
  1151.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  1152.     AppleTest_ContainerMethodDebug("AppleTest_Container","InstallObjectAccessors");
  1153.  
  1154.     SOM_TRY
  1155.     
  1156.     InstallStaticCallbacks( _fSemtIntf, (SIHelper*)_fSemtIntf->GetSIHelper(ev),
  1157.             _fSession );
  1158.  
  1159.     SOM_CATCH_ALL_ENDTRY
  1160. }
  1161.  
  1162. //------------------------------------------------------------------------------
  1163. // AppleTest_ContainerGetEmbeddedFrames
  1164. //------------------------------------------------------------------------------
  1165.  
  1166. SOM_Scope OrderedCollection*  SOMLINK AppleTest_ContainerGetEmbeddedFrames(AppleTest_Container *somSelf, Environment *ev)
  1167. {
  1168.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  1169.     AppleTest_ContainerMethodDebug("AppleTest_Container","GetEmbeddedFrames");
  1170.  
  1171.     SOM_TRY
  1172.     
  1173.     return _fEmbeddedFrames;
  1174.  
  1175.     SOM_CATCH_ALL_ENDTRY
  1176.     return kODNULL;
  1177. }
  1178.  
  1179. //------------------------------------------------------------------------------
  1180. // AppleTest_ContainerGetDisplayFrames
  1181. //------------------------------------------------------------------------------
  1182.  
  1183. SOM_Scope OrderedCollection*  SOMLINK AppleTest_ContainerGetDisplayFrames(AppleTest_Container *somSelf, Environment *ev)
  1184. {
  1185.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  1186.     AppleTest_ContainerMethodDebug("AppleTest_Container","GetDisplayFrames");
  1187.  
  1188.     SOM_TRY
  1189.     
  1190.     return _fDisplayFrames;
  1191.  
  1192.     SOM_CATCH_ALL_ENDTRY
  1193.     return kODNULL;
  1194. }
  1195.  
  1196. SOM_Scope Proxy*  SOMLINK AppleTest_ContainerProxyForFrameID(AppleTest_Container *somSelf, Environment *ev,
  1197.         ODID frameID)
  1198. {
  1199.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  1200.     AppleTest_ContainerMethodDebug("AppleTest_Container","ProxyForFrameID");
  1201.  
  1202.     SOM_TRY
  1203.     
  1204.     ODFrame* frame = somSelf->GetStorageUnit(ev)->GetDraft(ev)->AcquireFrame(ev, frameID);
  1205.     Proxy* p = somSelf->ProxyForFrame(ev, frame);
  1206.     frame->Release(ev);
  1207.     return p;
  1208.  
  1209.     SOM_CATCH_ALL_ENDTRY
  1210.     return kODNULL;
  1211. }
  1212.  
  1213. SOM_Scope void  SOMLINK AppleTest_ContainerHighlightSelection(AppleTest_Container *somSelf, Environment *ev)
  1214. {
  1215.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  1216.     AppleTest_ContainerMethodDebug("AppleTest_Container","HighlightSelection");
  1217.  
  1218.     SOM_TRY
  1219.     
  1220.     switch (_fSelection->Count())
  1221.     {
  1222.         case 0:        // no selection
  1223.             break;
  1224.  
  1225.         case 1:        // single selection
  1226.             {    OrderedCollectionIterator i(_fSelection);
  1227.                 somSelf->HighlightProxyBorder(ev, (Proxy*) i.First());
  1228.             };
  1229.             break;
  1230.  
  1231.         default:    // multiple selection
  1232.             {    Proxy* p;
  1233.                 OrderedCollectionIterator i(_fSelection);
  1234.                 for (p = (Proxy*) i.First(); i.IsNotComplete(); p = (Proxy*) i.Next())
  1235.                 {    if (_fSelection->Contains(p))
  1236.                         somSelf->HighlightContentObject(ev, p);
  1237.                 }
  1238.             }
  1239.     }
  1240.  
  1241.     SOM_CATCH_ALL_ENDTRY
  1242. }
  1243.  
  1244. SOM_Scope void  SOMLINK AppleTest_ContainerHighlightProxyBorder(AppleTest_Container *somSelf, Environment *ev,
  1245.         Proxy* p)
  1246. {
  1247.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  1248.     AppleTest_ContainerMethodDebug("AppleTest_Container","HighlightProxyBorder");
  1249.  
  1250.     SOM_TRY
  1251.     
  1252.     ODUnused(p);
  1253.  
  1254.     if ( _fSelectRgn )
  1255.     {
  1256.         // draw frame border
  1257. #ifdef THINK_CPLUS
  1258.         FillRgn(_fSelectRgn, ODQDGlobals.gray);
  1259.         FillRgn(_fCornerHandleRgn, ODQDGlobals.black);
  1260.         FillRgn(_fEdgeHandleRgn, ODQDGlobals.black);
  1261. #else
  1262.         FillRgn(_fSelectRgn, &(ODQDGlobals.gray));
  1263.         FillRgn(_fCornerHandleRgn, &(ODQDGlobals.black));
  1264.         FillRgn(_fEdgeHandleRgn, &(ODQDGlobals.black));
  1265. #endif
  1266.     }    
  1267.  
  1268.     SOM_CATCH_ALL_ENDTRY
  1269. }
  1270.  
  1271. SOM_Scope void  SOMLINK AppleTest_ContainerHighlightContentObject(AppleTest_Container *somSelf, Environment *ev,
  1272.         Proxy* p)
  1273. {
  1274.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  1275.     AppleTest_ContainerMethodDebug("AppleTest_Container","HighlightContentObject");
  1276.  
  1277.     SOM_TRY
  1278.     
  1279.     ODUnused(p);
  1280.  
  1281.     SOM_CATCH_ALL_ENDTRY
  1282. }
  1283.  
  1284. SOM_Scope void  SOMLINK AppleTest_ContainerClipEmbeddedFacets(AppleTest_Container *somSelf, Environment *ev,
  1285.         ODFacet* facet)
  1286. {
  1287.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  1288.     AppleTest_ContainerMethodDebug("AppleTest_Container","ClipEmbeddedFacets");
  1289.  
  1290.     SOM_TRY
  1291.     
  1292.     ODGeometryMode geoMode = GetCanvasGeometryMode(ev, facet->GetCanvas(ev));
  1293.  
  1294.     ODShape* shape;
  1295.     if ( facet->GetFrame(ev)->IsRoot(ev) )
  1296.         shape = facet->GetFrame(ev)->AcquireFrameShape(ev, kODNULL);
  1297.     else
  1298.         shape = facet->AcquireClipShape(ev, kODNULL);
  1299.         
  1300.     ODShape* workingClip = ODCopyAndRelease(ev, shape);
  1301.     workingClip->SetGeometryMode(ev,geoMode);
  1302.  
  1303.     // let selection obscure embedded parts
  1304.  
  1305.     RgnHandle tempRgn;
  1306.     ODShape* tempShape = workingClip->NewShape(ev);
  1307.     
  1308.     if (_fSelectRgn && !EmptyRgn(_fSelectRgn))
  1309.     {
  1310.         tempRgn = ODNewRgn();
  1311.         CopyRgn(_fSelectRgn, tempRgn);
  1312.         tempShape->SetPlatformShape(ev, kODQuickDraw, tempRgn);
  1313.         workingClip->Subtract(ev, tempShape);
  1314.     }
  1315.  
  1316.     if (_fCornerHandleRgn && !EmptyRgn(_fCornerHandleRgn))
  1317.     {
  1318.         tempRgn = ODNewRgn();
  1319.         CopyRgn(_fCornerHandleRgn, tempRgn);
  1320.         tempShape->SetPlatformShape(ev, kODQuickDraw, tempRgn);
  1321.         workingClip->Subtract(ev, tempShape);
  1322.     }
  1323.  
  1324.     if (_fEdgeHandleRgn && !EmptyRgn(_fEdgeHandleRgn))
  1325.     {
  1326.         tempRgn = ODNewRgn();
  1327.         CopyRgn(_fEdgeHandleRgn, tempRgn);
  1328.         tempShape->SetPlatformShape(ev, kODQuickDraw, tempRgn);
  1329.         workingClip->Subtract(ev, tempShape);
  1330.     }
  1331.  
  1332.     tempShape->Release(ev);
  1333.     
  1334.     ODFacet* embFacet;    
  1335.     ODFacetIterator* facets = facet->CreateFacetIterator(ev, kODChildrenOnly, kODFrontToBack);
  1336.     for (embFacet = facets->First(ev);
  1337.             facets->IsNotComplete(ev);
  1338.             embFacet = facets->Next(ev))
  1339.     {
  1340.         TempODShape newClipShape = ODCopyAndRelease(ev, embFacet->GetFrame(ev)->AcquireFrameShape(ev, kODNULL));
  1341.         newClipShape->SetGeometryMode(ev,geoMode);
  1342.         TempODShape newMaskShape = ODCopyAndRelease(ev, embFacet->GetFrame(ev)->AcquireUsedShape(ev, kODNULL));
  1343.  
  1344.         TempODTransform wclipTrans = embFacet->AcquireExternalTransform(ev, kODNULL);
  1345.  
  1346.         newClipShape->Transform(ev, wclipTrans);            // now in containing frame coordinates
  1347.         newClipShape->Intersect(ev, workingClip);
  1348.         newClipShape->InverseTransform(ev, wclipTrans);        // now in embedded frame coordinates
  1349.         embFacet->ChangeGeometry(ev, newClipShape, kODNULL, kODNULL);
  1350.  
  1351.         // Comment out these two lines and newMaskShape above to test #1243157 
  1352.         newMaskShape->Transform(ev, wclipTrans);            // now in containing frame coordinates
  1353.         workingClip->Subtract(ev, newMaskShape);
  1354.  
  1355.     }
  1356.     delete facets;
  1357.     
  1358.     // loop to clip for part content here
  1359.     
  1360.     workingClip->Release(ev);
  1361.  
  1362.     SOM_CATCH_ALL_ENDTRY
  1363. }
  1364.  
  1365. SOM_Scope void  SOMLINK AppleTest_ContainerEmptySelection(AppleTest_Container *somSelf, Environment *ev)
  1366. {
  1367.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  1368.     AppleTest_ContainerMethodDebug("AppleTest_Container","EmptySelection");
  1369.  
  1370.     SOM_TRY
  1371.     
  1372.     for(ODULong i = _fSelection->Count(); i > 0; i--)
  1373.     {
  1374.         Proxy* sp = (Proxy*) _fSelection->RemoveFirst();
  1375.         // Don't unselect facets unless the frame is still embedded in this part. [cc]
  1376.         // The frame may have been moved to another part.
  1377.         TempODFrame tempFrame = sp->frame->AcquireContainingFrame(ev);
  1378.         TempODPart tempPart = tempFrame->AcquirePart(ev);
  1379.         if ( tempPart == _fPartWrapper )
  1380.         {
  1381.             ODFrameFacetIterator* facets = sp->frame->CreateFacetIterator(ev);
  1382.             for (ODFacet* f1 = facets->First(ev); facets->IsNotComplete(ev); f1 = facets->Next(ev))
  1383.             {
  1384.                 if ( f1->IsSelected(ev) )
  1385.                 {
  1386.                     f1->SetSelected(ev, kODFalse);
  1387.                 }
  1388.             }
  1389.             delete facets;
  1390.         }
  1391.     }
  1392.     SetEmptyRgn(_fSelectRgn);
  1393.     SetEmptyRgn(_fCornerHandleRgn);
  1394.     SetEmptyRgn(_fEdgeHandleRgn);
  1395.  
  1396.     SOM_CATCH_ALL_ENDTRY
  1397. }
  1398.  
  1399. SOM_Scope ODBoolean  SOMLINK AppleTest_ContainerHandleMouseDown(AppleTest_Container *somSelf, Environment *ev,
  1400.         ODFacet* facet,
  1401.         ODPoint* where,
  1402.         ODEventData* event)
  1403. {
  1404.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  1405.     AppleTest_ContainerMethodDebug("AppleTest_Container","HandleMouseDown");
  1406.  
  1407.     SOM_TRY
  1408.     
  1409. #if defined(ODDebug) && ODDebugActivates
  1410.         somPrintf("Draw %d::MouseDown: Calling IsActive\n", somSelf->GetID(ev));
  1411. #endif
  1412.     if (!facet->GetWindow(ev)->IsActive(ev))
  1413.     {
  1414. #if defined(ODDebug) && ODDebugActivates
  1415.         somPrintf("Draw %d::Mouse Down: Calling Select\n", somSelf->GetID(ev));
  1416. #endif
  1417.         //facet->GetWindow(ev)->Select(ev);
  1418.     }
  1419.     else
  1420.         somSelf->ActivateFrame(ev, facet->GetFrame(ev));
  1421.  
  1422.     Point mouse;
  1423.     { TempODTransform xForm = facet->AcquireWindowContentTransform(ev, kODNULL);
  1424.       ODPoint inv = *where;
  1425.       xForm->InvertPoint(ev, &inv);
  1426.       mouse = inv.AsQDPoint();
  1427.     }
  1428.  
  1429.     if (facet->GetWindow(ev) == _fPalette) 
  1430.     {
  1431.         RgnHandle bRgn;
  1432.         { TempODShape frameShape = facet->GetFrame(ev)->AcquireFrameShape(ev, kODNULL);
  1433.           bRgn = frameShape->GetQDRegion(ev);
  1434.         }
  1435.         
  1436.         Rect        bRect;
  1437.         ODUShort    height;
  1438.         ODUShort    whichColor;
  1439.         ODBoolean    didHitMargin;
  1440.         
  1441.         bRect.left = (**bRgn).rgnBBox.left;
  1442.         bRect.top = (**bRgn).rgnBBox.top;
  1443.         bRect.bottom = (**bRgn).rgnBBox.bottom;
  1444.         bRect.right = (**bRgn).rgnBBox.right;
  1445.         height = ((bRect.bottom - bRect.top) - kMargin - ((kNumColors-1) * kMargin) - kMargin) / kNumColors;
  1446.         
  1447.         whichColor = mouse.v / (kMargin + height);
  1448.         didHitMargin = ((mouse.v  % (kMargin + height)) < kMargin) || 
  1449.                         (mouse.h < kMargin) || 
  1450.                         ((mouse.h + kMargin) >  bRect.right);
  1451.         
  1452.         if (didHitMargin == kODFalse) {
  1453.             OrderedCollectionIterator aIter(_fDisplayFrames);
  1454.             
  1455.             ODFrame*    displayFrame;
  1456.             for (displayFrame = (ODFrame*) aIter.First(); aIter.IsNotComplete(); displayFrame = (ODFrame*) aIter.Next())
  1457.             {
  1458.                 ODFrameFacetIterator*    facets = displayFrame->CreateFacetIterator(ev);
  1459.                 for (ODFacet* facet = (ODFacet*) facets->First(ev);
  1460.                         facets->IsNotComplete(ev);
  1461.                         facet = (ODFacet*) facets->Next(ev))
  1462.                 {
  1463.                     if (facet->GetWindow(ev) != _fPalette)
  1464.                     {
  1465.                         somSelf->SetBGColor1(ev, displayFrame, whichColor);
  1466.                         displayFrame->Invalidate(ev, kODNULL, kODNULL);
  1467.                     }
  1468.                 }
  1469.                 delete facets;
  1470.             }
  1471.         }
  1472.     }
  1473.     else {
  1474.     
  1475.         OrderedCollectionIterator i(_fSelection);
  1476.         Proxy* p = (Proxy*)i.First();
  1477.     
  1478.         Point qdWhere = where->AsQDPoint();
  1479.         
  1480.         if (_fSelection->Count() != 0)
  1481.         {
  1482.             if (PtInRgn(mouse, _fCornerHandleRgn))
  1483.                 return somSelf->HandleMouseDownCornerResize(ev, facet, p, &mouse);
  1484.             else if (PtInRgn(mouse, _fEdgeHandleRgn))
  1485.                 return somSelf->HandleMouseDownEdgeResize(ev, facet, p, &mouse);
  1486.             else if (PtInRgn(mouse, _fSelectRgn))
  1487.                 return somSelf->HandleMouseDownDrag(ev, facet, p, event);
  1488.             else
  1489.                 switch (_fSelection->Count())
  1490.                 {
  1491.                     case 0:
  1492.                         break;
  1493.                 
  1494.                     case 1:
  1495.                         somSelf->InvalidateSelection(ev, facet->GetFrame(ev));
  1496.                         somSelf->EmptySelection(ev);
  1497.                         somSelf->ClipEmbeddedFrames(ev, facet->GetFrame(ev));
  1498.                         break;
  1499.                         
  1500.                     default:
  1501.                         // !!! handle multiple selection
  1502.                         break;
  1503.                 }
  1504.         }
  1505.         else
  1506.         {
  1507.             if (!_fDrawingLines && (event->modifiers & controlKey))
  1508.             {
  1509.                  somSelf->StartDrawingLines(ev, facet->GetFrame(ev));
  1510.                 gLastPoint = mouse;
  1511.             }
  1512.         }
  1513.     }
  1514.  
  1515.     return kODTrue;
  1516.  
  1517.     SOM_CATCH_ALL_ENDTRY
  1518.     return kODFalse;
  1519. }
  1520.  
  1521.  
  1522. SOM_Scope ODBoolean  SOMLINK AppleTest_ContainerHandleBGMouseDown(AppleTest_Container *somSelf, Environment *ev,
  1523.         ODFacet* facet,
  1524.         ODPoint* where,
  1525.         ODEventData* event)
  1526. {
  1527.     /*    When handling a background mouse-down, I'm interested only in handling drags
  1528.         of selected frames. */
  1529.         
  1530.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  1531.     AppleTest_ContainerMethodDebug("AppleTest_Container","HandleBGMouseDown");
  1532.     
  1533.      SOM_TRY
  1534.     
  1535.       if (facet->GetWindow(ev) == _fPalette)
  1536.         return kODFalse;
  1537.     if( _fSelection->Count() != 1 )        // Container doesn't handle multiple drags.
  1538.         return kODFalse;
  1539.  
  1540.     Point mouse;
  1541.     { TempODTransform xForm = facet->AcquireWindowContentTransform(ev, kODNULL);
  1542.       ODPoint inv = *where;
  1543.       xForm->InvertPoint(ev, &inv);
  1544.       mouse = inv.AsQDPoint();
  1545.     }
  1546.             
  1547.     if( ! PtInRgn(mouse,_fSelectRgn) )
  1548.         return kODFalse;
  1549.         
  1550.     OrderedCollectionIterator i(_fSelection);
  1551.     Proxy* p = (Proxy*)i.First();
  1552.     return somSelf->HandleMouseDownDrag(ev, facet, p, event);
  1553.  
  1554.      SOM_CATCH_ALL
  1555.      SOM_ENDTRY
  1556.      return kODFalse;
  1557. }
  1558.  
  1559.  
  1560. SOM_Scope ODBoolean  SOMLINK AppleTest_ContainerHandleMouseDownDrag(AppleTest_Container *somSelf, Environment *ev,
  1561.         ODFacet* facet,
  1562.         Proxy* selection,
  1563.         ODEventData* event)
  1564. {
  1565.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  1566.     AppleTest_ContainerMethodDebug("AppleTest_Container","HandleMouseDownDrag");
  1567.  
  1568.      SOM_TRY
  1569.     
  1570.     ODSLong savedRefNum;
  1571.     BeginUsingLibraryResources(savedRefNum);
  1572.     SetCursor(*GetCursor(284)); // Closed Hand Cursor 
  1573.     EndUsingLibraryResources(savedRefNum);
  1574.  
  1575.  
  1576.     ODBoolean handled = kODFalse;
  1577.     ODPart* destPart;
  1578.     ODShape* scratch;
  1579.     ODPoint translation (0,0);
  1580.     Point mdOffset = {0,0};
  1581.     RgnHandle dragRgn, tempRgn;
  1582.     ODDragAndDrop*    dad;
  1583.     ODStorageUnit*    unit;
  1584.     ODDropResult dropResult;
  1585.  
  1586.     // Build the drag outline
  1587.     ODShape* frameShape = selection->frame->AcquireFrameShape(ev, kODNULL);
  1588.     scratch = frameShape->Copy(ev);
  1589.     frameShape->Release(ev); frameShape = kODNULL;
  1590.     scratch->Transform(ev, selection->transform);
  1591.     dragRgn = scratch->CopyQDRegion(ev);
  1592.  
  1593.     Point QDtranslation;
  1594.     { TempODTransform  wfTrans = facet->AcquireWindowFrameTransform(ev, kODNULL);
  1595.       wfTrans->TransformPoint(ev, &translation);
  1596.       QDtranslation = translation.AsQDPoint();
  1597.     }
  1598.     
  1599.     LocalToGlobal(&QDtranslation);
  1600.     OffsetRgn(dragRgn, QDtranslation.h, QDtranslation.v);
  1601.     tempRgn = ODNewRgn();
  1602.     CopyRgn(dragRgn, tempRgn);
  1603.     InsetRgn(tempRgn, 1, 1);
  1604.     DiffRgn(dragRgn, tempRgn, dragRgn);
  1605.     ODDisposeHandle((Handle)tempRgn);
  1606.     scratch->Release(ev); scratch = kODNULL;
  1607.     
  1608.     // ••• Fill DAD SU with Props n' Vals
  1609.     
  1610.     dad = _fSession->GetDragAndDrop(ev);
  1611.     dad->Clear(ev);
  1612.     unit = dad->GetContentStorageUnit(ev);
  1613.  
  1614.     // • if dragging one frame, create the content frame property
  1615.     // This property cannot be promised, and must be written after the embedded part
  1616.     ODSUAddPropValue(ev, unit, kODPropContentFrame, kODStrongStorageUnitRef);
  1617.  
  1618.     // • if dragging one frame, clone the embedded part into the root storage unit
  1619.     // if the embedded part is savy, it will notice the kODPropContentFrame property
  1620.     // and promise its content
  1621.     ODDraft* fromDraft = somSelf->GetStorageUnit(ev)->GetDraft(ev);
  1622.     ODDraft* toDraft = unit->GetDraft(ev);
  1623.     ODDraftKey key = 0;
  1624.     ODID toRootID = 0;
  1625.     ODID toFrameID = 0;
  1626.     TRY
  1627.         key = fromDraft->BeginClone(ev, toDraft, kODNULL, kODCloneCut);    // May use cut or copy
  1628.         // Clone the embedded part to the root storage unit of the drag and drop container
  1629.         TempODPart tempPart = selection->frame->AcquirePart(ev);
  1630.         toRootID = fromDraft->Clone(ev, key, tempPart->GetID(ev), unit->GetID(ev), selection->frame->GetID(ev));
  1631.         // Clone the embedded frame to any storage unit; must be done after cloning the part because
  1632.         // the embedded frame strongly references the part.
  1633.         toFrameID = fromDraft->Clone(ev, key, selection->frame->GetID(ev), 0, selection->frame->GetID(ev));
  1634.         fromDraft->EndClone(ev, key);
  1635.     CATCH_ALL
  1636.         WARN("Draw: Clone to drag-and-drop container failed");
  1637.         if (key != 0)
  1638.             fromDraft->AbortClone(ev, key);
  1639.         RERAISE;
  1640.     ENDTRY
  1641.  
  1642.     if ( toFrameID )
  1643.     {
  1644.         ODSetWeakSURefProp(ev, unit, kODPropContentFrame, kODWeakStorageUnitRef, toFrameID);
  1645.         // Weakly reference the frame so it must be explicitly cloned into the receiving draft
  1646.     }
  1647.  
  1648.     // • (optional) save offset between mousedown pt and topLeft pt of selection
  1649.     
  1650.     Point topLeft;
  1651.     {     TempODFrameFacetIterator faceti(ev,selection->frame);
  1652.         TempODTransform  wfTrans = faceti.Current()->AcquireWindowFrameTransform(ev, kODNULL);
  1653.         topLeft = wfTrans->GetQDOffset(ev);
  1654.     }
  1655.     
  1656.     mdOffset = event->where;
  1657.     GlobalToLocal(&mdOffset);
  1658.     
  1659.     SubPt(topLeft,&mdOffset);
  1660.     
  1661.     unit->AddProperty(ev, kODPropMouseDownOffset);
  1662.     StorageUnitSetPromiseValue(unit, ev, kQDPoint, 0, sizeof(Point)/2, (ODValue) &(mdOffset.v), _fPartWrapper);
  1663.     StorageUnitSetPromiseValue(unit, ev, kQDPoint, sizeof(Point)/2, sizeof(Point)/2, (ODValue) &(mdOffset.h), _fPartWrapper);
  1664.             
  1665.     // • (optional) if dragging one frame, save its external transform (not aggregate)
  1666.     // $$$$$ Should use StdTypIO to do portable streaming of "point"
  1667.     ODSUAddPropValue(ev, unit, kODPropExternalTransform, kQDPoint);
  1668.     StorageUnitSetValue(unit, ev, sizeof(Point), (ODValue) &topLeft);
  1669.  
  1670.     // • if dragging one frame, write its shape   [jpa]
  1671.     unit->AddProperty(ev, kODPropSuggestedFrameShape);
  1672.     TempODShape tempShape = selection->frame->AcquireFrameShape(ev, kODNULL);
  1673.     tempShape->WriteShape(ev, unit);
  1674.  
  1675.     // Write out the dragged frame's ID in case it is dropped back to this part.
  1676.     unit->AddProperty(ev, kPropFrameInfo);
  1677.     StorageUnitSetPromiseValue(unit, ev, kDrawFrameID, 0, sizeof(ODID), &selection, _fPartWrapper);
  1678.  
  1679.     // Just to test whether GetPromiseValue works
  1680.     {
  1681.         const ODULong kBufferSize = 255;
  1682.         ODByteArray ba;
  1683.         ODPart* part = kODNULL;
  1684.         ODULong length = unit->GetPromiseValue(ev, kDrawFrameID, 0, kBufferSize, &ba, &part);    
  1685.         if ((length != sizeof(ODID)) || (part != _fPartWrapper)) {
  1686.             WARN("GetPromiseValue fails!");
  1687.         }
  1688.         ODDisposePtr(ba._buffer);
  1689.     }
  1690.     
  1691.     dadSelection = selection;
  1692.     
  1693.     selection->frame->SetDragging(ev, kODTrue);
  1694.     
  1695.     ODByteArray dragRgnBA = CreateByteArrayStruct(&dragRgn, sizeof(RgnHandle));
  1696.     ODByteArray eventBA = CreateByteArrayStruct(&event, sizeof(ODEventData*));
  1697.     selection->frame->SetInLimbo(ev, kODTrue);
  1698.     dropResult = dad->StartDrag(ev, facet->GetFrame(ev), kODDragImageRegionHandle,
  1699.             &dragRgnBA, &destPart, &eventBA);
  1700.     DisposeByteArrayStruct(dragRgnBA);
  1701.     DisposeByteArrayStruct(eventBA);
  1702.     
  1703.     dadSelection = kODNULL;
  1704.     
  1705.     if ( dropResult != kODDropMove )
  1706.         selection->frame->SetInLimbo(ev, kODFalse);
  1707.     
  1708.     if ( (dropResult == kODDropCopy) || (dropResult == kODDropMove) )
  1709.     {
  1710.         if (destPart == _fPartWrapper)
  1711.         {
  1712.             // The frame was dropped within the same part
  1713.             if (dropResult == kODDropMove)
  1714.                 facet->GetFrame(ev)->Invalidate(ev, kODNULL, kODNULL);
  1715.             selection->frame->SetDragging(ev, kODFalse);                
  1716.         }
  1717.         else if (dropResult == kODDropMove)
  1718.         {
  1719. #if ODDebug
  1720.         somPrintf("Draw %d::Drag: Cleaning up after move\n", somSelf->GetID(ev));
  1721. #endif
  1722.             // The frame was moved out
  1723.             facet->GetFrame(ev)->Invalidate(ev, kODNULL, kODNULL);
  1724.             // $$$$$ Doesn't invalidating the containing frame make the next line unnecessary
  1725.             somSelf->InvalidateSelection(ev, selection->frame);    // $$$$$ The frame has been moved elsewhere
  1726.             somSelf->EmptySelection(ev);
  1727.             
  1728.             OrderedCollection* tempFacets = new OrderedCollection;
  1729.             
  1730. #if ODDebug
  1731.         somPrintf("Draw %d::Drag: Deleting old facets\n", somSelf->GetID(ev));
  1732. #endif
  1733.             // Get all facets displaying the moved frame
  1734.             // Necessary because they can't be deleted during iteration
  1735.             // We can't use the frame's facet iterator because the destination
  1736.             // of the move will have changed the frame's containing frame,
  1737.             // which eliminates all facets.
  1738.             ODFacetIterator* facets = facet->CreateFacetIterator(ev, kODChildrenOnly, kODFrontToBack);
  1739.             for (ODFacet* f1 = facets->First(ev);
  1740.                     facets->IsNotComplete(ev);
  1741.                     f1 = facets->Next(ev))
  1742.             {
  1743.                 if ( f1->GetFrame(ev) == selection->frame )
  1744.                     tempFacets->AddLast(f1);
  1745.             }
  1746.             delete facets;
  1747.             
  1748.             // Now delete all facets displaying the moved frame
  1749.             OrderedCollectionIterator t(tempFacets);
  1750.             for (ODFacet* f2 = (ODFacet*)t.First();
  1751.                     t.IsNotComplete();
  1752.                     f2 = (ODFacet*)t.Next())
  1753.             {
  1754. #if ODDebug
  1755.                 somPrintf("Draw:: Deleting facet displaying moved frame\n");
  1756. #endif
  1757.                 f2->GetContainingFacet(ev)->RemoveFacet(ev, f2);
  1758.                 ODDeleteObject(f2);
  1759.             }
  1760.             delete tempFacets;
  1761.  
  1762.             ODFrame* movedFrame = selection->frame;
  1763.  
  1764. #if ODDebug
  1765.         somPrintf("Draw %d::Drag: Deleting old proxy\n", somSelf->GetID(ev));
  1766. #endif
  1767.             movedFrame->Acquire(ev); // So that when we Remove/Release it below, we are using a valid pointer
  1768.             
  1769.             // Remove our proxy for the moved frame
  1770.             somSelf->DeleteFrameProxy(ev, selection);  // NOTE: this implicitly releases movedFrame!
  1771.             
  1772.             if ( movedFrame->IsInLimbo(ev) )
  1773.             {
  1774.                 movedFrame->SetContainingFrame(ev, kODNULL); // force close of part windows
  1775.                 movedFrame->Remove(ev);
  1776.             }
  1777.             else
  1778.                 movedFrame->Release(ev);
  1779.             movedFrame = kODNULL;
  1780.             
  1781. #if ODDebug
  1782.         somPrintf("Draw %d::Drag: Resetting cliping\n", somSelf->GetID(ev));
  1783. #endif
  1784.             // Reset clipping of the remaining embedded facets
  1785.             somSelf->ClipEmbeddedFrames(ev, facet->GetFrame(ev));
  1786.  
  1787.             somSelf->GetStorageUnit(ev)->GetDraft(ev)->SetChangedFromPrev(ev);
  1788.         }
  1789.         else
  1790.         {
  1791.             // The frame was copied
  1792.             selection->frame->SetDragging(ev, kODFalse);
  1793.         }
  1794.         
  1795.         handled = kODTrue;
  1796.     }
  1797.     else // dropResult == kODDropFail
  1798.     {
  1799.         selection->frame->SetDragging(ev, kODFalse);
  1800.     }
  1801.     ODDisposeHandle((Handle)dragRgn);
  1802.     ODReleaseObject(ev, destPart);
  1803.     
  1804.     return handled;
  1805.  
  1806.      SOM_CATCH_ALL
  1807.      SOM_ENDTRY
  1808.      return kODFalse;
  1809. }
  1810.  
  1811. SOM_Scope ODBoolean  SOMLINK AppleTest_ContainerHandleMouseDownEdgeResize(AppleTest_Container *somSelf, Environment *ev,
  1812.         ODFacet* facet,
  1813.         Proxy* selection,
  1814.         Point* mouse)
  1815. {
  1816.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  1817.     AppleTest_ContainerMethodDebug("AppleTest_Container","HandleMouseDownEdgeResize");
  1818.  
  1819.      SOM_TRY
  1820.     
  1821.     enum edge {kNone, kTE, kLE, kBE, kRE};
  1822.     edge growEdge = kNone;
  1823.  
  1824.     Rect* sr = somSelf->GetSelectionRectLocal(ev, selection);
  1825.  
  1826.     if        (mouse->v <= ((*sr).top + (0.1 * (*sr).top))) growEdge = kTE;
  1827.     else if (mouse->h <= ((*sr).left + (0.1 * (*sr).left))) growEdge = kLE;
  1828.     else if (mouse->v >= ((*sr).bottom - (0.1 * (*sr).bottom))) growEdge = kBE;
  1829.     else if (mouse->h >= ((*sr).right -  (0.1 * (*sr).right))) growEdge = kRE;
  1830.  
  1831.     somSelf->SetGrafPortOrigin(ev, facet);
  1832.     Rect growBox = (*sr);
  1833.     Rect oldBox = {0,0,0,0};
  1834.     delete sr; sr = kODNULL;
  1835.     
  1836.     PenMode(patXor);
  1837. #ifdef THINK_CPLUS
  1838.     PenPat(ODQDGlobals.gray);
  1839. #else
  1840.     PenPat(&(ODQDGlobals.gray));
  1841. #endif
  1842.     
  1843.     Point theLoc = {0,0};
  1844.     Point lastLoc = {0,0};
  1845.     
  1846.     while (StillDown())
  1847.     {
  1848.         GetMouse(&theLoc);
  1849.         
  1850.         if ((theLoc.h != lastLoc.h) || (theLoc.v != lastLoc.v))
  1851.         {
  1852.             switch (growEdge) 
  1853.             {
  1854.                 case kTE:
  1855.                     growBox.top = theLoc.v;
  1856.                     break;
  1857.  
  1858.                 case kLE:
  1859.                     growBox.left = theLoc.h;
  1860.                     break;
  1861.  
  1862.                 case kBE:
  1863.                     growBox.bottom = theLoc.v;
  1864.                     break;
  1865.  
  1866.                 case kRE:
  1867.                     growBox.right = theLoc.h;
  1868.                     break;
  1869.                 
  1870.                 default:
  1871.                     break;
  1872.             }
  1873.             FrameRect(&oldBox);
  1874.             FrameRect(&growBox);
  1875.         }
  1876.         
  1877.         lastLoc = theLoc;
  1878.         oldBox = growBox;
  1879.     }
  1880.     
  1881.     FrameRect(&oldBox);
  1882.     
  1883. #ifdef THINK_CPLUS
  1884.     PenPat(ODQDGlobals.gray);
  1885. #else
  1886.     PenPat(&(ODQDGlobals.gray));
  1887. #endif
  1888.     PenMode(patCopy);
  1889.     
  1890.     SetOrigin(0,0);
  1891.  
  1892.     Point delta;
  1893.     delta.h = theLoc.h - mouse->h; //where.h;
  1894.     delta.v = theLoc.v - mouse->v; //where.v;
  1895.     Point transOffset = { 0, 0 };
  1896.  
  1897.     TempODShape oldShape = selection->frame->AcquireFrameShape(ev, kODNULL);
  1898.     ODRect newBounds;
  1899.     oldShape->GetBoundingBox(ev, &newBounds);
  1900.  
  1901.     switch (growEdge)
  1902.     {
  1903.         case kTE:
  1904.             newBounds.bottom -= ff(delta.v);
  1905.             transOffset.v += delta.v;
  1906.             break;
  1907.  
  1908.         case kLE:
  1909.             newBounds.right -= ff(delta.h);
  1910.             transOffset.h += delta.h;
  1911.             break;
  1912.  
  1913.         case kBE:
  1914.             newBounds.bottom += ff(delta.v);
  1915.             break;
  1916.  
  1917.         case kRE:
  1918.             newBounds.right += ff(delta.h);
  1919.             break;
  1920.  
  1921.         default:
  1922.             break;
  1923.     }
  1924.     
  1925.     TempODShape newShape = oldShape->NewShape(ev);
  1926.     newShape->SetRectangle(ev, &newBounds);
  1927.     
  1928.     somSelf->InvalEmbedFrameAfterResize(ev, facet, selection, oldShape, newShape, &transOffset);
  1929.     
  1930.     return kODTrue;
  1931.  
  1932.      SOM_CATCH_ALL
  1933.      SOM_ENDTRY
  1934.      return kODFalse;
  1935. }
  1936.  
  1937. SOM_Scope ODBoolean  SOMLINK AppleTest_ContainerHandleMouseDownCornerResize(AppleTest_Container *somSelf, Environment *ev,
  1938.         ODFacet* facet,
  1939.         Proxy* selection,
  1940.         Point* mouse)
  1941. {
  1942.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  1943.     AppleTest_ContainerMethodDebug("AppleTest_Container","HandleMouseDownCornerResize");
  1944.  
  1945.      SOM_TRY
  1946.     
  1947.     enum corner {kNone, kTL, kTR, kBL, kBR};
  1948.     corner growCorner = kNone;
  1949.  
  1950.     Rect* sr = somSelf->GetSelectionRectLocal(ev, selection);
  1951.     Point center;
  1952.     SetPt(¢er, ((*sr).right + (*sr).left) / 2, ((*sr).bottom + (*sr).top) / 2);        // center of FrameShape
  1953.     
  1954.     if        ((mouse->v <= center.v) && (mouse->h <= center.h)) growCorner = kTL;
  1955.     else if ((mouse->v <  center.v) && (mouse->h >  center.h)) growCorner = kTR;
  1956.     else if ((mouse->v >  center.v) && (mouse->h <  center.h)) growCorner = kBL;
  1957.     else if ((mouse->v >  center.v) && (mouse->h >  center.h)) growCorner = kBR;
  1958.         
  1959.     somSelf->SetGrafPortOrigin(ev, facet);
  1960.     Rect growBox = (*sr);
  1961.     Rect oldBox = {0,0,0,0};
  1962.     delete sr; sr = kODNULL;
  1963.     
  1964.     PenMode(patXor);
  1965. #ifdef THINK_CPLUS
  1966.     PenPat(ODQDGlobals.gray);
  1967. #else
  1968.     PenPat(&(ODQDGlobals.gray));
  1969. #endif
  1970.     
  1971.     Point theLoc = {0,0};
  1972.     Point lastLoc = {0,0};
  1973.  
  1974.     while (StillDown())
  1975.     {
  1976.         GetMouse(&theLoc);
  1977.         
  1978.         if ((theLoc.h != lastLoc.h) || (theLoc.v != lastLoc.v))
  1979.         {
  1980.             switch (growCorner) 
  1981.             {
  1982.                 case kTL:
  1983.                     growBox.top = theLoc.v;
  1984.                     growBox.left = theLoc.h;
  1985.                     break;
  1986.  
  1987.                 case kTR:
  1988.                     growBox.top = theLoc.v;
  1989.                     growBox.right = theLoc.h;
  1990.                     break;
  1991.  
  1992.                 case kBL:
  1993.                     growBox.left = theLoc.h;
  1994.                     growBox.bottom = theLoc.v;
  1995.                     break;
  1996.  
  1997.                 case kBR:
  1998.                     growBox.bottom = theLoc.v;
  1999.                     growBox.right = theLoc.h;
  2000.                     break;
  2001.                 
  2002.                 default:
  2003.                     break;
  2004.             }
  2005.             
  2006.             FrameRect(&oldBox);
  2007.             FrameRect(&growBox);
  2008.         }
  2009.         
  2010.         lastLoc = theLoc;
  2011.         oldBox = growBox;
  2012.     }
  2013.     
  2014.     FrameRect(&oldBox);
  2015.     
  2016. #ifdef THINK_CPLUS
  2017.     PenPat(ODQDGlobals.gray);
  2018. #else
  2019.     PenPat(&(ODQDGlobals.gray));
  2020. #endif
  2021.     PenMode(patCopy);
  2022.     
  2023.     SetOrigin(0,0);
  2024.  
  2025.     Point delta;
  2026.     delta.h = theLoc.h - mouse->h; //where.h;
  2027.     delta.v = theLoc.v - mouse->v; //where.v;
  2028.     Point transOffset = { 0, 0 };
  2029.  
  2030.     TempODShape oldShape = selection->frame->AcquireFrameShape(ev, kODNULL);
  2031.     ODRect newBounds;
  2032.     oldShape->GetBoundingBox(ev, &newBounds);
  2033.     ODPoint fixDelta = delta;
  2034.  
  2035.     switch (growCorner)
  2036.     {
  2037.         case kTL:
  2038.             newBounds.bottom -= fixDelta.y; newBounds.right -= fixDelta.x;
  2039.             transOffset.v += delta.v; transOffset.h += delta.h;
  2040.             break;
  2041.  
  2042.         case kTR:
  2043.             newBounds.bottom -= fixDelta.y; newBounds.right += fixDelta.x;
  2044.             transOffset.v += delta.v;
  2045.             break;
  2046.  
  2047.         case kBL:
  2048.             newBounds.bottom += fixDelta.y; newBounds.right -= fixDelta.x;
  2049.             transOffset.h += delta.h;
  2050.             break;
  2051.  
  2052.         case kBR:
  2053.             newBounds.bottom += fixDelta.y;
  2054.             newBounds.right += fixDelta.x;
  2055.             break;
  2056.  
  2057.         default:
  2058.             break;
  2059.     }
  2060.  
  2061.     TempODShape newShape = oldShape->NewShape(ev);
  2062.     newShape->SetRectangle(ev, &newBounds);
  2063.  
  2064.     somSelf->InvalEmbedFrameAfterResize(ev, facet, selection, oldShape, newShape, &transOffset);
  2065.     
  2066.     return kODTrue;
  2067.  
  2068.      SOM_CATCH_ALL
  2069.      SOM_ENDTRY
  2070.      return kODFalse;
  2071. }
  2072.  
  2073. SOM_Scope ODBoolean  SOMLINK AppleTest_ContainerHandleMouseDownInEmbeddedFrame(AppleTest_Container *somSelf, Environment *ev,
  2074.         ODFacet* container,
  2075.         ODFacet* facet,
  2076.         ODPoint* where,
  2077.         ODEventData* event)
  2078. {
  2079.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  2080.     AppleTest_ContainerMethodDebug("AppleTest_Container","HandleMouseDownInEmbeddedFrame");
  2081.  
  2082.      SOM_TRY
  2083.     
  2084.     ODUnused(where);
  2085.     ODUnused(event);
  2086.  
  2087.     ODBoolean result = (event->what != kODEvtBGMouseDownEmbedded);
  2088.  
  2089.     Proxy* p = somSelf->ProxyForFrame(ev, facet->GetFrame(ev));
  2090.  
  2091.     switch (_fSelection->Count())
  2092.     {
  2093.         case 0:
  2094.             if( event->what == kODEvtBGMouseDownEmbedded )
  2095.                 break;
  2096.             _fSelection->AddFirst((ElementType)p);
  2097.             facet->SetSelected(ev, kODTrue);
  2098.             somSelf->CreateProxySelectionBorder(ev, p);
  2099.             somSelf->ClipEmbeddedFrames(ev, container->GetFrame(ev));
  2100.             somSelf->InvalidateSelection(ev, container->GetFrame(ev));
  2101.             container->GetWindow(ev)->Update(ev);
  2102.             if ( WaitMouseMoved(event->where) )
  2103.             {
  2104.                 somSelf->HandleMouseDownDrag(ev, container, p, event);
  2105.                 result = kODTrue;
  2106.             }
  2107.             else
  2108.             {
  2109.             }
  2110.             break;
  2111.  
  2112.         case 1:
  2113.             if ( WaitMouseMoved(event->where) )
  2114.             {
  2115.                 somSelf->HandleMouseDownDrag(ev, container, p, event);
  2116.                 result = kODTrue;
  2117.             }
  2118.             else
  2119.             {
  2120. #if defined(ODDebug) && ODDebugActivates
  2121.         somPrintf("Draw %d::Mouse Down Embedded: Calling IsActive\n", somSelf->GetID(ev));
  2122. #endif
  2123.                 if (!container->GetWindow(ev)->IsActive(ev))
  2124.                 {
  2125. #if defined(ODDebug) && ODDebugActivates
  2126.         somPrintf("Draw %d::Mouse Down Embedded: Calling Select\n", somSelf->GetID(ev));
  2127. #endif
  2128.                     container->GetWindow(ev)->Select(ev);
  2129.                 }
  2130.                 else
  2131.                     somSelf->ActivateFrame(ev, container->GetFrame(ev));
  2132.                 
  2133.                 if( event->what == kODEvtBGMouseDownEmbedded )
  2134.                     break;
  2135.                 ODBoolean wasSelected = facet->IsSelected(ev);
  2136.                 
  2137.                 somSelf->InvalidateSelection(ev, container->GetFrame(ev));
  2138.                 somSelf->EmptySelection(ev);
  2139.                 
  2140.                 if ( !wasSelected )
  2141.                 {
  2142.                     _fSelection->AddFirst((ElementType)p);
  2143.                     facet->SetSelected(ev, kODTrue);
  2144.                     somSelf->CreateProxySelectionBorder(ev, p);
  2145.                 }
  2146.                 
  2147.                 somSelf->ClipEmbeddedFrames(ev, container->GetFrame(ev));
  2148.                 somSelf->InvalidateSelection(ev, container->GetFrame(ev));
  2149.             }
  2150.             break;
  2151.             
  2152.         default:
  2153.             // !!! handle multiple selection
  2154.             break;
  2155.     }
  2156.  
  2157.     somSelf->InvalidateSelection(ev, container->GetFrame(ev));
  2158.     //return somSelf->HandleMouseDownDrag(ev, container, p, event);
  2159.  
  2160.     _fSession->GetDispatcher(ev)->InvalidateFacetUnderMouse(ev);
  2161.     return result;
  2162.  
  2163.      SOM_CATCH_ALL
  2164.      SOM_ENDTRY
  2165.      return kODFalse;
  2166. }
  2167.  
  2168. SOM_Scope ODBoolean  SOMLINK AppleTest_ContainerHandleKeyDown(AppleTest_Container *somSelf, Environment *ev,
  2169.         ODFrame* focusFrame,
  2170.         ODEventData* event)
  2171. {
  2172.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  2173.     AppleTest_ContainerMethodDebug("AppleTest_Container","HandleKeyDown");
  2174.  
  2175.      SOM_TRY
  2176.     
  2177.     ODUnused(focusFrame);
  2178.     ODUnused(event);
  2179.     // cursor keys? !!!
  2180.  
  2181.     return kODFalse;
  2182.  
  2183.      SOM_CATCH_ALL
  2184.      SOM_ENDTRY
  2185.      return kODFalse;
  2186. }
  2187.  
  2188. SOM_Scope ODBoolean  SOMLINK AppleTest_ContainerHandleMenuEvent(AppleTest_Container *somSelf, Environment *ev,
  2189.         ODFrame* focusFrame,
  2190.         ODEventData* event)
  2191. {
  2192.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  2193.     AppleTest_ContainerMethodDebug("AppleTest_Container","HandleMenuEvent");
  2194.  
  2195.      SOM_TRY
  2196.     
  2197.     ASSERTM(_fMenuBar != kODNULL, 0, "Menubar is NULL");
  2198.     
  2199.     long menuResult = event->message;
  2200.     short menu = HiWord(menuResult);
  2201.     short item = LoWord(menuResult);
  2202.     ODCommandID command = _fMenuBar->GetCommand(ev, menu, item);
  2203.     ODBoolean handled = kODFalse;
  2204.     
  2205.     // Until such time as we clean this up and register all commands:
  2206.     if (!_fMenuBar->IsCommandSynthetic(ev, command))
  2207.     {
  2208.         switch (command)
  2209.         {
  2210.             case kODCommandAbout:
  2211.                 {
  2212.                     ODArbitrator* fArbitrator = _fSession->GetArbitrator(ev);
  2213.                     ODWindowState* fWindowState = _fSession->GetWindowState(ev);
  2214.                     ODTypeToken fModalFocus = _fSession->Tokenize(ev, kODModalFocus);
  2215.                     TempODFrame currentOwner = fArbitrator->AcquireFocusOwner(ev, fModalFocus);
  2216.                     if (fArbitrator->RequestFocus(ev, fModalFocus,focusFrame))
  2217.                     {
  2218.                         short itemHit;
  2219.                         SetCursor(&ODQDGlobals.arrow);
  2220.                         ModalFilterUPP modalFilter = NewModalFilterProc(AboutDialogFilter);
  2221.                         
  2222.                         ODSLong        savedRefNum;
  2223.                         BeginUsingLibraryResources(savedRefNum);
  2224.                         DialogPtr aboutDialog = GetNewDialog(128 ,0,(WindowPtr)-1L);
  2225.                         EndUsingLibraryResources(savedRefNum);
  2226.                 
  2227.                         if (aboutDialog)
  2228.                         {
  2229.                             fWindowState->DeactivateFrontWindows(ev);
  2230.                             ShowWindow(aboutDialog);
  2231.                             ModalDialog(modalFilter, &itemHit);
  2232.                             DisposeDialog(aboutDialog);
  2233.                             fWindowState->ActivateFrontWindows(ev);
  2234.                         }
  2235.                         DisposeRoutineDescriptor(modalFilter);
  2236.                 
  2237.                         fArbitrator->TransferFocus(ev, fModalFocus,focusFrame, currentOwner);    
  2238.                         handled = kODTrue;    
  2239.                     }
  2240.                     else
  2241.                         SysBeep(2);
  2242.                 }
  2243.                 break;
  2244.             case kODCommandPageSetup:
  2245.                 if (focusFrame->IsRoot(ev))
  2246.                 handled = somSelf->HandlePageSetup(ev, focusFrame);
  2247.                 break;
  2248.             case kODCommandPrint:
  2249.                 if (focusFrame->IsRoot(ev))
  2250.                 handled = somSelf->HandlePrinting(ev, focusFrame);
  2251.                 break;
  2252.             
  2253.             case kODCommandCut: 
  2254.                 handled = somSelf->DoCut(ev, focusFrame); break;
  2255.             case kODCommandCopy:
  2256.                 handled = somSelf->DoCopy(ev, focusFrame); break;
  2257.             case kODCommandPaste:
  2258.                 handled = somSelf->DoPaste(ev, focusFrame); break;
  2259.             case kODCommandPasteAs:
  2260.                 handled = somSelf->DoPasteLink(ev, focusFrame); break;
  2261.             case kODCommandClear:
  2262.                 handled = somSelf->DoClear(ev, focusFrame); break;
  2263.             case kODCommandSelectAll:
  2264.                 handled = somSelf->DoSelectAll(ev, focusFrame); break;
  2265.             
  2266.             case cGray:
  2267.             case cRed:
  2268.             case cGreen:
  2269.             case cYellow:
  2270.             case cBlue:
  2271.             case cMagenta:
  2272.             case cCyan:
  2273.             case cWhite:
  2274. #ifdef BETASEEDMODS
  2275.             case cOtherColor:
  2276. #endif
  2277.                 {    //!!! This whole method do with some cleanup
  2278.                     // Change SetBGColor to use a command number
  2279.                     short menu;
  2280.                     short item;
  2281.                     _fMenuBar->GetMenuAndItem(ev, command, &menu, &item);
  2282.                     somSelf->SetBGColor1(ev, focusFrame, item-1);
  2283.                     handled = kODTrue;
  2284.                 }
  2285.                 break;
  2286. #ifndef BETASEEDMODS
  2287.             case cOtherColor:
  2288.                 _fPaletteUp = kODTrue;
  2289.                 somSelf->ShowPalette(ev);
  2290.                 handled = kODTrue;
  2291.             break;
  2292. #endif
  2293.  
  2294. #ifdef SCRIPTDEBUG
  2295.             case cToggleScripting :
  2296.                 _fScriptingOn = !_fScriptingOn;
  2297.                 somSelf->GetStorageUnit(ev)->GetDraft(ev)->SetChangedFromPrev(ev);
  2298.                 handled = kODTrue;
  2299.                 break;
  2300. #endif
  2301.             case kODCommandOpen :
  2302.                 {
  2303.                     Proxy* p;
  2304.                     OrderedCollectionIterator i(_fSelection);
  2305.                     for (p = (Proxy*) i.First(); i.IsNotComplete(); p = (Proxy*) i.Next())
  2306.                     {    
  2307.                         ODFrame* frame = p->frame;
  2308.                         TempODPart part = frame ? frame->AcquirePart(ev) : kODNULL;
  2309.                         if (part)
  2310.                         {
  2311.                             part->Open(ev, frame);
  2312.                             break;
  2313.                         }
  2314.                     }
  2315.                 }
  2316.                 handled = kODTrue;
  2317.                 break;
  2318.                 
  2319.             case kODCommandViewAsWin :
  2320.                 somSelf->Open(ev, focusFrame);
  2321.                 handled = kODTrue;
  2322.                 break;
  2323.                 
  2324.             case kODCommandGetPartInfo : 
  2325.                 {
  2326.                     Proxy* p;
  2327.                     OrderedCollectionIterator i(_fSelection);
  2328.                     p = (Proxy*) i.First();
  2329.  
  2330.                     ODFrame* theFrame = p==kODNULL?focusFrame:p->frame;
  2331.                     TempODFrameFacetIterator facets(ev,theFrame);
  2332.                     ODInfo* info = _fSession->GetInfo(ev);
  2333.                     ODDraftPermissions perms = somSelf->GetStorageUnit(ev)->
  2334.                                                               GetDraft(ev)->
  2335.                                                               GetPermissions(ev);
  2336.                     info->ShowPartFrameInfo( ev, 
  2337.                                              facets.Current(),
  2338.                                              HAS_WRITE_ACCESS(perms));
  2339. #if ODDebug
  2340.                     theFrame->Invalidate(ev, (ODShape*)kODNULL, kODNULL);
  2341. #endif            
  2342.                     handled = kODTrue;
  2343.                 }
  2344.                 break;
  2345. #if TESTING_DIALOG_TSMTE
  2346.             case kODBringUpTestTSMTEDialog:
  2347.                 BringUpTSMTETestDialog(ev, somSelf, focusFrame);
  2348.                 handled = kODTrue;
  2349.                 break;
  2350. #endif
  2351. #ifndef NUKE_PARTSBIN_FOR_DR
  2352.             case kODCommandShowPartsBin:
  2353.                 somSelf->DoShowPartsBin(ev, focusFrame);
  2354.                 handled = kODTrue;
  2355.                 break;
  2356. #endif
  2357.             case kODCommandPreferences:
  2358.                 SysBeep(10); SysBeep(10);
  2359.                 break;
  2360.  
  2361.             default:
  2362.                 break;
  2363.         }
  2364.                 
  2365.     }
  2366.     else
  2367.     {
  2368.         short menu;
  2369.         short item;
  2370.         _fMenuBar->GetMenuAndItem(ev, command, &menu, &item);
  2371.         
  2372.         if (menu == kDrawColorMenuID)
  2373.         {
  2374.             if (item == kNumColors) {
  2375.                 _fPaletteUp = kODTrue;
  2376.                 somSelf->ShowPalette(ev);
  2377.                 handled = kODTrue;
  2378.             }
  2379.             else {
  2380.                 somSelf->SetBGColor1(ev, focusFrame, item-1);
  2381.                 focusFrame->Invalidate(ev, kODNULL, kODNULL);
  2382.                 handled = kODTrue;
  2383.             }
  2384.         }
  2385.         else if (menu == kDrawEmbedMenuID)
  2386.         {
  2387.             switch (_fSelection->Count())
  2388.             {
  2389.                 case 0:
  2390.                     break;
  2391.         
  2392.                 case 1:
  2393.                     somSelf->InvalidateSelection(ev, focusFrame);
  2394.                     somSelf->EmptySelection(ev);
  2395.                     somSelf->ClipEmbeddedFrames(ev, focusFrame);
  2396.                     break;
  2397.                     
  2398.                 default:
  2399.                     // !!! handle multiple selection
  2400.                     break;
  2401.             }
  2402.             ODPart* newPart;
  2403.             somSelf->Embed(ev, item, focusFrame, &newPart);
  2404.             handled = kODTrue;
  2405.         }
  2406. #ifndef BETASEEDMODS
  2407.         else if (menu == kDrawFrameMenuID)
  2408.         {
  2409.             if (item == 1)
  2410.             {
  2411.                 Proxy* p;
  2412.                 OrderedCollectionIterator i(_fSelection);
  2413.                 for (p = (Proxy*) i.First(); i.IsNotComplete(); p = (Proxy*) i.Next())
  2414.                 {    
  2415.                     p->frame->SetFrozen(ev, true);
  2416.                 }
  2417.             }
  2418.             else if (item == 2)    
  2419.             {
  2420.                 Proxy* p;
  2421.                 OrderedCollectionIterator i(_fSelection);
  2422.                 for (p = (Proxy*) i.First(); i.IsNotComplete(); p = (Proxy*) i.Next())
  2423.                 {    
  2424.                     p->frame->SetFrozen(ev, false);
  2425.                 }
  2426.             }
  2427.             handled = kODTrue;
  2428.         }
  2429. #endif
  2430.     }
  2431.     
  2432. //    SetPort(curPort);
  2433.     HiliteMenu(0);
  2434.     return handled;
  2435.  
  2436.      SOM_CATCH_ALL
  2437.      SOM_ENDTRY
  2438.      return kODFalse;
  2439. }
  2440.  
  2441. #ifndef _STORUTIL_
  2442. #include <StorUtil.h>
  2443. #endif
  2444.  
  2445. #pragma segment DrawPartPrinting
  2446.  
  2447. SOM_Scope void  SOMLINK AppleTest_ContainerDoShowPartsBin(AppleTest_Container *somSelf, Environment *ev,
  2448.         ODFrame* frame)
  2449. {
  2450.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  2451.     AppleTest_ContainerMethodDebug("AppleTest_Container","DoShowPartsBin");
  2452.  
  2453.     SOM_TRY
  2454.     
  2455.     // partsbin code stolen from clock.cpp
  2456.     
  2457. #ifndef NUKE_PARTSBIN_FOR_DR
  2458.     if ( _fPartsBinOpen )
  2459.     {
  2460.         if ( _fPartsBinWin != 0 )
  2461.         {
  2462.             TempODWindow pbWin = _fSession->GetWindowState(ev)->AcquireWindow(ev, _fPartsBinWin);
  2463.             // ASSERTM(pbWin != kODNULL, kODErrCannotAcquireWindow, "Cannot Hide Parts Bin");
  2464.     
  2465.             pbWin->Hide(ev);
  2466.             _fPartsBinOpen = kODFalse;
  2467.         }
  2468.     }
  2469.     else
  2470.     {
  2471.         ODPart*                partsbin = kODNULL;
  2472.         ODStorageUnit*        su = somSelf->GetStorageUnit(ev);
  2473.  
  2474.         if (!su->Exists(ev, kODPropPartsBin,kODStrongStorageUnitRef,0))
  2475.         {    
  2476.             partsbin = su->GetDraft(ev)->CreatePart(ev, kODKindPartsBin, kODNULL);
  2477.             ASSERTM(partsbin != kODNULL, kODErrCannotCreatePart, "Cannot Create Parts Bin");
  2478.             
  2479.             ODSetStrongSURefProp(ev, su, kODPropPartsBin, kODStrongStorageUnitRef, partsbin->GetStorageUnit(ev)->GetID(ev));
  2480.         }
  2481.         else
  2482.         {
  2483.             partsbin = su->GetDraft(ev)->AcquirePart(ev, 
  2484.                             ODGetStrongSURefProp(ev, su, kODPropPartsBin,kODStrongStorageUnitRef));
  2485.         }
  2486.         
  2487.         _fPartsBinWin = partsbin->Open(ev, kODNULL);
  2488.         _fPartsBinOpen = kODTrue;
  2489.         ODReleaseObject(ev, partsbin);
  2490.     }
  2491. #endif
  2492.  
  2493.     SOM_CATCH_ALL_ENDTRY
  2494. }
  2495.  
  2496. SOM_Scope void  SOMLINK AppleTest_ContainerStartDrawingLines(AppleTest_Container *somSelf, Environment *ev,
  2497.         ODFrame* frame)
  2498. {
  2499.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  2500.     AppleTest_ContainerMethodDebug("AppleTest_Container","StartDrawingLines");
  2501.     
  2502.     if (_fSession->GetArbitrator(ev)->RequestFocus(ev, _fSession->Tokenize(ev, kODMouseFocus), frame))
  2503.     {
  2504.         _fDrawingLines = kODTrue;
  2505.     }
  2506. }
  2507.  
  2508. SOM_Scope void  SOMLINK AppleTest_ContainerStopDrawingLines(AppleTest_Container *somSelf, Environment *ev,
  2509.         ODFrame* frame)
  2510. {
  2511.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  2512.     AppleTest_ContainerMethodDebug("AppleTest_Container","StopDrawingLines");
  2513.  
  2514.     if (_fDrawingLines)
  2515.     {
  2516.         SysBeep(2);
  2517.         _fDrawingLines = kODFalse;
  2518.         _fSession->GetArbitrator(ev)->RelinquishFocus(ev, _fSession->Tokenize(ev, kODMouseFocus),frame);  
  2519.     } 
  2520. }
  2521.  
  2522. SOM_Scope ODBoolean  SOMLINK AppleTest_ContainerHandlePageSetup(AppleTest_Container *somSelf, Environment *ev,
  2523.         ODFrame* focusFrame)
  2524. {
  2525.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  2526.     AppleTest_ContainerMethodDebug("AppleTest_Container","HandlePageSetup");
  2527.  
  2528.     SOM_TRY
  2529.     
  2530.     ODUnused(focusFrame);
  2531.     PrOpen();
  2532.     ASSERTM(PrError() == noErr, PrError(), "DrawPart could not open the PageSetup dialog");
  2533.     
  2534.     if (!_fPrintRecord)
  2535.     {
  2536.         somSelf->CreateDefPrintRec(ev);
  2537.     }
  2538.     
  2539.     if (PrStlDialog(_fPrintRecord))
  2540.     {
  2541.         // • externalize contents to part su
  2542.         ODSUForceFocus(ev, _fTestDrawSU, kODPropPrintingInfo,kTPrintRec);
  2543.             
  2544.         ODULong oldsize = _fTestDrawSU->GetSize(ev);
  2545.         ODULong newsize = GetHandleSize((Handle)_fPrintRecord);
  2546.         
  2547.         HLock((Handle)_fPrintRecord);
  2548.         _fTestDrawSU->SetOffset(ev, 0);
  2549.         StorageUnitSetValue(_fTestDrawSU, ev, newsize,(ODPtr)(*_fPrintRecord));
  2550.         
  2551.         if (oldsize > newsize)
  2552.             _fTestDrawSU->DeleteValue(ev, oldsize-newsize);
  2553.     }
  2554.     
  2555.     PrClose();
  2556.     
  2557.     return kODTrue;
  2558.  
  2559.     SOM_CATCH_ALL_ENDTRY
  2560.     return kODFalse;
  2561. }
  2562.  
  2563. SOM_Scope ODBoolean  SOMLINK AppleTest_ContainerHandlePrinting(AppleTest_Container *somSelf, Environment *ev,
  2564.         ODFrame* focusFrame)
  2565. {
  2566.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  2567.     AppleTest_ContainerMethodDebug("AppleTest_Container","HandlePrinting");
  2568.  
  2569.     SOM_TRY
  2570.     
  2571.     PrOpen();
  2572.     ASSERTM(PrError() == noErr, PrError(), "DrawPart could not open the PageSetup dialog");
  2573.     
  2574.     if (!_fPrintRecord)
  2575.     {
  2576.         somSelf->CreateDefPrintRec(ev);
  2577.     }
  2578.     
  2579.     if (PrJobDialog(_fPrintRecord))
  2580.     {
  2581.         somSelf->PrintDocument(ev, focusFrame);
  2582.     }
  2583.     
  2584.     PrClose();
  2585.     
  2586.     return kODTrue;
  2587.  
  2588.     SOM_CATCH_ALL_ENDTRY
  2589.     return kODFalse;
  2590. }
  2591.  
  2592. SOM_Scope void  SOMLINK AppleTest_ContainerCreateDefPrintRec(AppleTest_Container *somSelf, Environment *ev)
  2593. {
  2594.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  2595.     AppleTest_ContainerMethodDebug("AppleTest_Container","CreateDefPrintRec");
  2596.  
  2597.     SOM_TRY
  2598.     
  2599.     _fPrintRecord = (THPrint) ODNewHandle(sizeof(TPrint));
  2600.     if (!_fPrintRecord)
  2601.     {
  2602.         THROW(kODErrOutOfMemory);
  2603.     }
  2604.     
  2605.     PrintDefault(_fPrintRecord);
  2606.  
  2607.     SOM_CATCH_ALL_ENDTRY
  2608. }
  2609.  
  2610.  
  2611. SOM_Scope ODFacet*  SOMLINK AppleTest_ContainerBeginPrinting(AppleTest_Container *somSelf, Environment *ev,
  2612.         ODFrame* rootFrame,
  2613.         TPrPort* thePrPort)
  2614. {
  2615.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  2616.     AppleTest_ContainerMethodDebug("AppleTest_Container","BeginPrinting");
  2617.  
  2618.     SOM_TRY
  2619.     
  2620.     TempODTransform xtransform = rootFrame->CreateTransform(ev);
  2621.     
  2622.     Rect pagerect = (**_fPrintRecord).prInfo.rPage;
  2623.     
  2624.     TempODShape clipshape = rootFrame->CreateShape(ev);
  2625.     ODRect cliprect(pagerect);
  2626.     clipshape->SetRectangle(ev, &cliprect);
  2627.  
  2628.     ODFacet* prFacet = _fSession->GetWindowState(ev)->
  2629.         CreateFacet(ev, rootFrame, clipshape, xtransform, kODNULL, kODNULL);
  2630.  
  2631.     ODCanvas* prCanvas = prFacet->CreateCanvas(ev, kODQuickDraw,
  2632.                                         (ODPlatformCanvas)thePrPort, kODFalse, kODFalse);
  2633.     prCanvas->SetPlatformPrintJob(ev, kODQuickDraw, (ODPlatformCanvas)_fPrintRecord);
  2634.     prCanvas->SetOwner(ev, _fPartWrapper);
  2635.     prFacet->ChangeCanvas(ev, prCanvas);
  2636.     
  2637.     rootFrame->FacetAdded(ev, prFacet);
  2638.     
  2639.     return prFacet;
  2640.  
  2641.     SOM_CATCH_ALL_ENDTRY
  2642.     return kODNULL;
  2643. }
  2644.  
  2645. SOM_Scope void  SOMLINK AppleTest_ContainerPrintPage(AppleTest_Container *somSelf, Environment *ev,
  2646.         ODFacet* prFacet,
  2647.         ODUShort page)
  2648. {
  2649.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  2650.     AppleTest_ContainerMethodDebug("AppleTest_Container","PrintPage");
  2651.  
  2652.     SOM_TRY
  2653.     
  2654.     Rect pageSize = (**_fPrintRecord).prInfo.rPage;
  2655.     ODRect bbox;
  2656.     Rect frect;
  2657.     
  2658.     TempODShape frameShape = prFacet->GetFrame(ev)->AcquireFrameShape(ev, kODNULL);
  2659.     frameShape->GetBoundingBox(ev, &bbox);
  2660.     bbox.AsQDRect(frect);
  2661.     
  2662.     ODULong height = frect.bottom;
  2663.     ODULong width  = frect.right;
  2664.     
  2665.     Point         pt = {0,0};
  2666.     ODUShort     locator = page-1;
  2667.     
  2668.     while (locator)
  2669.     {
  2670.         pt.v += (pageSize.bottom+1);
  2671.         locator--;
  2672.  
  2673.         if (PtInRect(pt,&frect))
  2674.         {
  2675.             continue;
  2676.         }
  2677.         else
  2678.         {
  2679.             pt.v = 0;
  2680.             pt.h += (pageSize.right+1);
  2681.         }
  2682.     }
  2683.     
  2684.     TempODTransform xtransform = prFacet->CreateTransform(ev);
  2685.     
  2686.     xtransform->SetQDOffset(ev, &pt);
  2687.     
  2688.     Rect pagerect = (**_fPrintRecord).prInfo.rPage;
  2689.     
  2690.     TempODShape clipshape = prFacet->CreateShape(ev);
  2691.     ODRect cliprect(pagerect);
  2692.     clipshape->SetRectangle(ev, &cliprect);
  2693.     TempODShape invalshape = clipshape->Copy(ev); // DMc refcount - make temp
  2694.     clipshape->Transform(ev, xtransform);
  2695.     //clipshape->GetBoundingBox(&bbox);    // !!!
  2696.     xtransform->Invert(ev);
  2697.     prFacet->ChangeGeometry(ev, clipshape, xtransform, kODNULL);
  2698.  
  2699.     prFacet->Update(ev, invalshape, kODNULL); // DMc refcount - use temp
  2700.  
  2701.     SOM_CATCH_ALL_ENDTRY
  2702. }
  2703.  
  2704. SOM_Scope void  SOMLINK AppleTest_ContainerEndPrinting(AppleTest_Container *somSelf, Environment *ev,
  2705.         ODFacet* prFacet)
  2706. {
  2707.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  2708.     AppleTest_ContainerMethodDebug("AppleTest_Container","EndPrinting");
  2709.  
  2710.     SOM_TRY
  2711.     
  2712.     ODCanvas* prCanvas = prFacet->GetCanvas(ev);
  2713.     
  2714.     prFacet->GetFrame(ev)->FacetRemoved(ev, prFacet);
  2715.     
  2716.     delete prCanvas;
  2717.     delete prFacet;
  2718.  
  2719.     SOM_CATCH_ALL_ENDTRY
  2720. }
  2721.  
  2722.  
  2723. ODUShort DetermineNumberOfPagesinDoc(Environment* ev, ODFrame* frame, Rect page)
  2724. {
  2725.     ODRect bbox;
  2726.     Rect frect;
  2727.     
  2728.     TempODShape frameShape = frame->AcquireFrameShape(ev, kODNULL);
  2729.     frameShape->GetBoundingBox(ev, &bbox);
  2730.     bbox.AsQDRect(frect);
  2731.     
  2732.     ODSLong height = frect.bottom;
  2733.     ODSLong width  = frect.right;
  2734.     
  2735.     ODUShort pages = 0;
  2736.     
  2737.     ODSLong wt = width;
  2738.     while (wt > 0)
  2739.     {
  2740.         ODSLong ht = height;
  2741.         while (ht > 0)
  2742.         {
  2743.             ht -= page.bottom;
  2744.             pages++;
  2745.         }
  2746.         
  2747.         wt -= page.right;
  2748.     }
  2749.     
  2750.     return pages;
  2751. }
  2752.  
  2753.  
  2754. SOM_Scope void  SOMLINK AppleTest_ContainerPrintDocument(AppleTest_Container *somSelf, Environment *ev,
  2755.         ODFrame* frame)
  2756. {
  2757.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  2758.     AppleTest_ContainerMethodDebug("AppleTest_Container","PrintDocument");
  2759.  
  2760.     SOM_TRY
  2761.     
  2762.     GrafPtr        oldPort;
  2763.     ODUShort    copies,
  2764.                 firstPage,
  2765.                 lastPage,
  2766.                 numberOfCopies,
  2767.                 printmgrsResFile,
  2768.                  realNumberOfPagesinDoc,
  2769.                 pageNumber,
  2770.                  PrintError;
  2771. //    THPrint        thePrRecHdl;
  2772.     TPPrPort    thePrPort;
  2773.     TPrStatus    theStatus;
  2774.     ODFacet*    prFacet;
  2775.  
  2776.     GetPort(&oldPort);
  2777.  
  2778.     PrOpen();
  2779.  
  2780.     if (PrError() == noErr)
  2781.     {
  2782.         /**
  2783.         Save the current resource file (i.e. the printer driver's) so
  2784.         the driver will not lose its resources upon return from the pIdleProc.
  2785.         **/
  2786.         printmgrsResFile = CurResFile();
  2787.  
  2788.         realNumberOfPagesinDoc = DetermineNumberOfPagesinDoc(ev, frame,(**_fPrintRecord).prInfo.rPage);
  2789.  
  2790.         numberOfCopies = (**_fPrintRecord).prJob.iCopies;
  2791.  
  2792.         firstPage = (**_fPrintRecord).prJob.iFstPage;
  2793.         lastPage = (**_fPrintRecord).prJob.iLstPage;
  2794.  
  2795.         (**_fPrintRecord).prJob.iFstPage = 1;
  2796.         (**_fPrintRecord).prJob.iLstPage = 9999;
  2797.  
  2798.         if (realNumberOfPagesinDoc < lastPage) 
  2799.             lastPage = realNumberOfPagesinDoc;
  2800.  
  2801.         //PrintingStatusDialog = GetNewDialog(257, nil, (WindowPtr) -1);
  2802.  
  2803.         for (copies = 1; copies <= numberOfCopies; copies++)
  2804.         {
  2805.             // Install a pointer to your pIdle proc in my print record.
  2806.             //(**thePrRecHdl).prJob.pIdleProc = checkMyPrintDialogButton;
  2807.  
  2808.             UseResFile(printmgrsResFile);
  2809.             thePrPort = PrOpenDoc(_fPrintRecord, nil, nil);
  2810.             
  2811.             if (PrError() == noErr)
  2812.             {
  2813.                 TRY
  2814.                     prFacet = somSelf->BeginPrinting(ev, frame, thePrPort);
  2815.                     THROW_IF_NULL(prFacet);
  2816.                     
  2817.                     pageNumber = firstPage;
  2818.                     while (pageNumber <= lastPage && PrError() == noErr)
  2819.                     {
  2820.                         PrOpenPage(thePrPort, nil);
  2821.     
  2822.                         if (PrError() == noErr) 
  2823.                         {
  2824.                             somSelf->PrintPage(ev, prFacet, pageNumber);
  2825.                         }
  2826.     
  2827.                         PrClosePage(thePrPort);
  2828.                         pageNumber++;
  2829.                     }
  2830.                     
  2831.                     somSelf->EndPrinting(ev, prFacet);
  2832.                 CATCH_ALL
  2833.                     // garbage collection needs to be improved
  2834.                 ENDTRY
  2835.                 
  2836.             }
  2837.             
  2838.             PrCloseDoc(thePrPort);
  2839.         }
  2840.     }
  2841.  
  2842.     if (((**_fPrintRecord).prJob.bJDocLoop == bSpoolLoop) && (PrError() == noErr))
  2843.         PrPicFile(_fPrintRecord, nil, nil, nil, &theStatus);
  2844.     
  2845.     PrintError = PrError();
  2846.     
  2847.     PrClose();
  2848.     
  2849.     THROW_IF_ERROR(PrintError);
  2850.     
  2851.     //if (PrintingStatusDialog != nil)
  2852.     //    DisposDialog(PrintingStatusDialog);
  2853.     
  2854.     SetPort(oldPort);
  2855.  
  2856.     SOM_CATCH_ALL_ENDTRY
  2857. }
  2858.  
  2859. SOM_Scope ODBoolean  SOMLINK AppleTest_ContainerDoCut(AppleTest_Container *somSelf, Environment *ev,
  2860.         ODFrame* frame)
  2861. {
  2862.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  2863.     AppleTest_ContainerMethodDebug("AppleTest_Container","DoCut");
  2864.  
  2865.     SOM_TRY
  2866.     
  2867.     ODUnused(frame);
  2868.     return kODFalse;
  2869.  
  2870.     SOM_CATCH_ALL_ENDTRY
  2871.     return kODFalse;
  2872. }
  2873.  
  2874. SOM_Scope ODBoolean  SOMLINK AppleTest_ContainerDoCopy(AppleTest_Container *somSelf, Environment *ev,
  2875.         ODFrame* frame)
  2876. {
  2877.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  2878.     AppleTest_ContainerMethodDebug("AppleTest_Container","DoCopy");
  2879.  
  2880.     SOM_TRY
  2881.     
  2882.     ODUnused(frame);
  2883.     return kODFalse;
  2884.  
  2885.     SOM_CATCH_ALL_ENDTRY
  2886.     return kODFalse;
  2887. }
  2888.  
  2889. SOM_Scope ODBoolean  SOMLINK AppleTest_ContainerDoPaste(AppleTest_Container *somSelf, Environment *ev,
  2890.         ODFrame* frame)
  2891. {
  2892.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  2893.     AppleTest_ContainerMethodDebug("AppleTest_Container","DoPaste");
  2894.  
  2895.     SOM_TRY
  2896.     
  2897.     ODUnused(frame);
  2898.     return kODFalse;
  2899.  
  2900.     SOM_CATCH_ALL_ENDTRY
  2901.     return kODFalse;
  2902. }
  2903.  
  2904. SOM_Scope ODBoolean  SOMLINK AppleTest_ContainerDoPasteLink(AppleTest_Container *somSelf, Environment *ev,
  2905.         ODFrame* frame)
  2906. {
  2907.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  2908.     AppleTest_ContainerMethodDebug("AppleTest_Container","DoPasteLink");
  2909.  
  2910.     SOM_TRY
  2911.     
  2912.     ODUnused(frame);
  2913.     return kODFalse;
  2914.  
  2915.     SOM_CATCH_ALL_ENDTRY
  2916.     return kODFalse;
  2917. }
  2918.  
  2919. SOM_Scope ODBoolean  SOMLINK AppleTest_ContainerDoClear(AppleTest_Container *somSelf, Environment *ev,
  2920.         ODFrame* frame)
  2921. {
  2922.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  2923.     AppleTest_ContainerMethodDebug("AppleTest_Container","DoClear");
  2924.  
  2925.     SOM_TRY
  2926.     
  2927.     OrderedCollectionIterator i(_fSelection);
  2928.     Proxy* selection = (Proxy*)i.First();
  2929.     
  2930.     if ( selection )
  2931.     {
  2932.         frame->Invalidate(ev, kODNULL, kODNULL);
  2933.         somSelf->EmptySelection(ev);
  2934.         
  2935.         OrderedCollection* tempFacets = new OrderedCollection;
  2936.         
  2937.         // Get all facets displaying the moved frame
  2938.         // Necessary because they can't be deleted during iteration
  2939.         // We can't use the frame's facet iterator because the destination
  2940.         // of the move will have changed the frame's containing frame,
  2941.         // which eliminates all facets.
  2942.         ODFrameFacetIterator* facets = selection->frame->CreateFacetIterator(ev);
  2943.         for (ODFacet* f1 = facets->First(ev);
  2944.                 facets->IsNotComplete(ev);
  2945.                 f1 = facets->Next(ev))
  2946.         {
  2947.             tempFacets->AddLast(f1);
  2948.         }
  2949.         delete facets;
  2950.         
  2951.         // Now delete all facets displaying the moved frame
  2952.         OrderedCollectionIterator t(tempFacets);
  2953.         for (ODFacet* f2 = (ODFacet*)t.First();
  2954.                 t.IsNotComplete();
  2955.                 f2 = (ODFacet*)t.Next())
  2956.         {
  2957.             f2->GetContainingFacet(ev)->RemoveFacet(ev, f2);
  2958.             ODDeleteObject(f2);
  2959.         }
  2960.         delete tempFacets;
  2961.     
  2962.         ODFrame* movedFrame = selection->frame;
  2963.     
  2964.         movedFrame->Acquire(ev); // So that when we Remove/Release it below, we are using a valid pointer
  2965.         
  2966.         // Remove our proxy for the moved frame
  2967.         somSelf->DeleteFrameProxy(ev, selection);  // NOTE: this implicitly releases movedFrame!
  2968.         
  2969.         // movedFrame->SetContainingFrame(ev, kODNULL);
  2970.         movedFrame->Remove(ev);
  2971.         movedFrame = kODNULL;
  2972.         
  2973.         // Reset clipping of the remaining embedded facets
  2974.         somSelf->ClipEmbeddedFrames(ev, frame);
  2975.     
  2976.         somSelf->GetStorageUnit(ev)->GetDraft(ev)->SetChangedFromPrev(ev);
  2977.         return kODTrue;
  2978.     }
  2979.     else
  2980.     {
  2981.         return kODFalse;
  2982.     }
  2983.  
  2984.     SOM_CATCH_ALL_ENDTRY
  2985.     return kODFalse;
  2986. }
  2987.  
  2988. SOM_Scope ODBoolean  SOMLINK AppleTest_ContainerDoSelectAll(AppleTest_Container *somSelf, Environment *ev,
  2989.         ODFrame* frame)
  2990. {
  2991.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  2992.     AppleTest_ContainerMethodDebug("AppleTest_Container","DoSelectAll");
  2993.  
  2994.     SOM_TRY
  2995.     
  2996.     ODUnused(frame);
  2997.     return kODFalse;
  2998.  
  2999.     SOM_CATCH_ALL_ENDTRY
  3000.     return kODFalse;
  3001. }
  3002.  
  3003. SOM_Scope void  SOMLINK AppleTest_ContainerActivateFrame(AppleTest_Container *somSelf, Environment *ev,
  3004.         ODFrame* frame)
  3005. {
  3006.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  3007.     AppleTest_ContainerMethodDebug("AppleTest_Container","ActivateFrame");
  3008.  
  3009.     SOM_TRY
  3010.     
  3011.     if (frame != (_fPalette ? _fPalette->GetRootFrame(ev) : kODNULL)) 
  3012.     {
  3013.         PartInfoRec* pInfo = (PartInfoRec*) frame->GetPartInfo(ev);
  3014.         WASSERTM(pInfo != kODNULL, "partInfo on activating frame is NULL");
  3015.         if (!(pInfo->fIsActive))
  3016.         {
  3017.             ODBoolean succeeded = false;
  3018.                                 
  3019.             succeeded = _fSession->GetArbitrator(ev)->RequestFocusSet(ev, _fFocusSet,frame);
  3020.                     
  3021.             if (succeeded)
  3022.             {
  3023.                 somSelf->FocusAcquired(ev, _fSelectionFocus, frame);
  3024.                 somSelf->FocusAcquired(ev, _fMenuFocus, frame);
  3025.                 somSelf->FocusAcquired(ev, _fKeyFocus, frame);
  3026.             }
  3027.         }
  3028.     }
  3029.  
  3030.     SOM_CATCH_ALL_ENDTRY
  3031. }
  3032.  
  3033. SOM_Scope void  SOMLINK AppleTest_ContainerDeActivateFrame(AppleTest_Container *somSelf, Environment *ev,
  3034.         ODFrame* frame)
  3035. {
  3036.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  3037.     AppleTest_ContainerMethodDebug("AppleTest_Container","DeActivateFrame");
  3038.  
  3039.     SOM_TRY
  3040.     
  3041.     if (frame != (_fPalette ? _fPalette->GetRootFrame(ev) : kODNULL)) {
  3042.         ODArbitrator* arbitrator = _fSession->GetArbitrator(ev);
  3043.  
  3044.         arbitrator->RelinquishFocusSet(ev, _fFocusSet,frame);
  3045.         somSelf->FocusLost(ev, _fSelectionFocus, frame);
  3046.         somSelf->FocusLost(ev, _fMenuFocus, frame);
  3047.         somSelf->FocusLost(ev, _fKeyFocus, frame);
  3048.  
  3049.         TempODFrame clipboardFocus = arbitrator->AcquireFocusOwner(ev, _fClipboardFocus);
  3050.         if ( frame == clipboardFocus )
  3051.         {
  3052.             arbitrator->RelinquishFocus(ev, _fClipboardFocus, frame);
  3053.             somSelf->FocusLost(ev, _fClipboardFocus, frame);
  3054.         }
  3055.     }
  3056.  
  3057.     SOM_CATCH_ALL_ENDTRY
  3058. }
  3059.  
  3060. SOM_Scope void  SOMLINK AppleTest_ContainerActivatingWindow(AppleTest_Container *somSelf, Environment *ev,
  3061.         ODFrame* frame)
  3062. {
  3063.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  3064.     AppleTest_ContainerMethodDebug("AppleTest_Container","ActivatingWindow");
  3065.  
  3066.     SOM_TRY
  3067.     
  3068. #if ODDebug
  3069.      // somPrintf("DrawPart Activate Event for frame %x\n", frame);
  3070. #endif
  3071.  
  3072.     PartInfoRec* pInfo = (PartInfoRec*) frame->GetPartInfo(ev);
  3073.     TempODFrame activeFrame = _fSession->GetArbitrator(ev)->AcquireFocusOwner(ev, _fSelectionFocus);
  3074.     if ((pInfo->fNeedsActivating)) // && (activeFrame == kODNULL))
  3075.     {
  3076. #if ODDebug
  3077.      // somPrintf("DrawPart: Need to activate frame %x\n", frame);
  3078. #endif
  3079.         somSelf->ActivateFrame(ev, frame);
  3080.         somSelf->ShowPalette(ev);
  3081.         pInfo->fNeedsActivating = kODFalse;
  3082.     }
  3083.  
  3084.     SOM_CATCH_ALL_ENDTRY
  3085. }
  3086.  
  3087. SOM_Scope void  SOMLINK AppleTest_ContainerDeActivatingWindow(AppleTest_Container *somSelf, Environment *ev,
  3088.         ODFrame* frame)
  3089. {
  3090.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  3091.     AppleTest_ContainerMethodDebug("AppleTest_Container","DeActivatingWindow");
  3092.  
  3093.     SOM_TRY
  3094.     
  3095. #if ODDebug
  3096.      // somPrintf("DrawPart Deactivate Event for frame %x\n", frame);
  3097. #endif
  3098.  
  3099.     PartInfoRec* pInfo = (PartInfoRec*) frame->GetPartInfo(ev);
  3100.     TempODFrame activeFrame = _fSession->GetArbitrator(ev)->AcquireFocusOwner(ev, _fSelectionFocus);
  3101.     if (frame == activeFrame)
  3102.     {
  3103. #if ODDebug
  3104.      // somPrintf("DrawPart: Will Need to activate frame %x\n", frame);
  3105. #endif
  3106.         pInfo->fNeedsActivating = kODTrue;
  3107.         //somSelf->DeActivateFrame(ev, frame);
  3108.     }
  3109.     else
  3110.     {
  3111. #if ODDebug
  3112.      // somPrintf("DrawPart: Won't Need to activate frame %x\n", frame);
  3113. #endif
  3114.         pInfo->fNeedsActivating = kODFalse;
  3115.     }
  3116.  
  3117.     SOM_CATCH_ALL_ENDTRY
  3118. }
  3119.  
  3120. SOM_Scope void  SOMLINK AppleTest_ContainerInstallMenus(AppleTest_Container *somSelf, Environment *ev,
  3121.         ODFrame* aFrame)
  3122. {
  3123.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  3124.     AppleTest_ContainerMethodDebug("AppleTest_Container","InstallMenus");
  3125.  
  3126.     SOM_TRY
  3127.     
  3128.     if (aFrame && _fMenuBar)
  3129.         _fMenuBar->Display(ev);
  3130.  
  3131.     SOM_CATCH_ALL_ENDTRY
  3132. }
  3133.  
  3134. SOM_Scope void  SOMLINK AppleTest_ContainerRemoveMenus(AppleTest_Container *somSelf, Environment *ev,
  3135.         ODFrame* aFrame)
  3136. {
  3137.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  3138.     AppleTest_ContainerMethodDebug("AppleTest_Container","RemoveMenus");
  3139.  
  3140.     SOM_TRY
  3141.     
  3142.     ODUnused(aFrame);
  3143.  
  3144. // Don't need to remove the menus we've added
  3145. // Just disable Shell menu items we've enabled
  3146.  
  3147.     SOM_CATCH_ALL_ENDTRY
  3148. }
  3149.  
  3150. SOM_Scope void  SOMLINK AppleTest_ContainerSetBGColor1(AppleTest_Container *somSelf, Environment *ev,
  3151.         ODFrame* aFrame,
  3152.         ODUShort whichColor)
  3153. {
  3154.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  3155.     AppleTest_ContainerMethodDebug("AppleTest_Container","SetBGColor1");
  3156.  
  3157.     SOM_TRY
  3158.     
  3159.     PartInfoRec* pInfo = (PartInfoRec *) aFrame->GetPartInfo(ev);
  3160.     if (!pInfo)
  3161.     {    pInfo = new PartInfoRec;
  3162.         aFrame->SetPartInfo(ev, (ODInfoType) pInfo);
  3163.     };
  3164.  
  3165.     RGBColor newColor = pInfo->bgColor;
  3166.     
  3167.     switch (whichColor)
  3168.     {
  3169.         case  kGray: newColor = rgbGray;        break;
  3170.         case  kRed: newColor = rgbRed;            break;
  3171.         case  kGreen: newColor = rgbGreen;        break;
  3172.         case  kYellow: newColor = rgbYellow;    break;
  3173.         case  kBlue: newColor = rgbBlue;        break;
  3174.         case  kMagenta: newColor = rgbMagenta;    break;
  3175.         case  kCyan: newColor = rgbCyan;        break;
  3176.         case  kWhite: newColor = rgbWhite;        break;
  3177.         case  kOther:
  3178.             {
  3179.                 Point where = {0, 0};
  3180.                 ConstStr255Param prompt = {"\pPick a new background color:"};
  3181.                 RGBColor outColor;
  3182.                 
  3183.                 if ( GetColor(where, prompt, &pInfo->bgColor, &outColor) )
  3184.                     newColor = outColor;
  3185.             }
  3186.             break;
  3187.         default: break;
  3188.     }
  3189.     somSelf->UserSetBGColor(ev, aFrame,&newColor);
  3190.  
  3191.     SOM_CATCH_ALL_ENDTRY
  3192. }
  3193.  
  3194. struct SetBGColorRec
  3195. {
  3196.     SetBGColorRec(RGBColor oldColor, RGBColor newColor, ODFrame* frame)
  3197.                     {_fOldColor = oldColor; _fNewColor = newColor;
  3198.                         _fFrame = frame;}
  3199.     RGBColor     _fOldColor;
  3200.     RGBColor     _fNewColor;
  3201.     ODFrame*    _fFrame;
  3202. };
  3203.  
  3204.  
  3205. SOM_Scope void  SOMLINK AppleTest_ContainerUserSetBGColor(AppleTest_Container *somSelf,
  3206.         Environment *ev,
  3207.         ODFrame* frame,
  3208.         RGBColor *whichColor)
  3209. {
  3210.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  3211.     AppleTest_ContainerMethodDebug("AppleTest_Container","UserSetBGColor");
  3212.  
  3213.     SOM_TRY
  3214.     
  3215.     PartInfoRec* pInfo = (PartInfoRec *) frame->GetPartInfo(ev);
  3216.     if (!pInfo)
  3217.     {    pInfo = new PartInfoRec;
  3218.         frame->SetPartInfo(ev, (ODInfoType) pInfo);
  3219.     }
  3220.     if (!RGBEqual(*whichColor,pInfo->bgColor))
  3221.     {
  3222.         ODIText*    undoActionName;
  3223.         ODIText*    redoActionName;
  3224.     
  3225.         ODScriptCode script = FontToScript( GetSysFont() );
  3226.         ODLangCode lang = GetScriptVariable(script, smScriptLang);
  3227.  
  3228.         undoActionName = CreateIText(script, lang, "\pUndo Set Color");
  3229.         redoActionName = CreateIText(script, lang, "\pRedo Set Color");
  3230.         SetBGColorRec* undoRec = new SetBGColorRec(pInfo->bgColor, *whichColor,
  3231.                                                     frame);
  3232.  
  3233.         // Cheat here. Only send the pointer. Assumes no one else will try
  3234.         //    to peak to the undo stack to look at our data.
  3235.         ODActionData    data = CreateByteArrayStruct(&undoRec,
  3236.                                                         sizeof(SetBGColorRec*));
  3237.         
  3238.         _fSession->GetUndo(ev)->AddActionToHistory(ev, _fPartWrapper, &data,
  3239.                                                 kODSingleAction,
  3240.                                                 (ODName*)undoActionName,
  3241.                                                 (ODName*)redoActionName);
  3242.  
  3243.         DisposeByteArrayStruct(data);
  3244.         DisposeIText(undoActionName);
  3245.         DisposeIText(redoActionName);
  3246.  
  3247.         somSelf->SetBGColor2(ev, frame, whichColor);
  3248.     }
  3249.  
  3250.     SOM_CATCH_ALL_ENDTRY
  3251. }
  3252.  
  3253. SOM_Scope void  SOMLINK AppleTest_ContainerSetBGColor2(AppleTest_Container *somSelf,
  3254.         Environment *ev,
  3255.         ODFrame* aFrame,
  3256.         RGBColor *whichColor)
  3257. {
  3258.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  3259.     AppleTest_ContainerMethodDebug("AppleTest_Container","SetBGColor2");
  3260.  
  3261.     SOM_TRY
  3262.     
  3263.     PartInfoRec* pInfo = (PartInfoRec *) aFrame->GetPartInfo(ev);
  3264.     if (!pInfo)
  3265.     {    pInfo = new PartInfoRec;
  3266.         aFrame->SetPartInfo(ev, (ODInfoType) pInfo);
  3267.     }
  3268.     if (!RGBEqual(*whichColor,pInfo->bgColor))
  3269.     {
  3270.         pInfo->bgColor = *whichColor;
  3271.         somSelf->GetStorageUnit(ev)->GetDraft(ev)->SetChangedFromPrev(ev);
  3272.         aFrame->Invalidate(ev, kODNULL, kODNULL);
  3273.     }
  3274.  
  3275.     SOM_CATCH_ALL_ENDTRY
  3276. }
  3277.  
  3278. SOM_Scope void  SOMLINK AppleTest_ContainerEmbed(AppleTest_Container *somSelf, Environment *ev,
  3279.         short item,
  3280.         ODFrame* frame,
  3281.         ODPart** newPart)
  3282. {
  3283.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  3284.     AppleTest_ContainerMethodDebug("AppleTest_Container","Embed");
  3285.  
  3286.     SOM_TRY
  3287.     
  3288.     if (item != 1)
  3289.         return;
  3290.         
  3291.     ODWindowState* windowState = _fSession->GetWindowState(ev);
  3292.     ODStorageUnit* su = somSelf->GetStorageUnit(ev);
  3293.     ODType    partkind = kODNULL;
  3294.  
  3295.     // StdGetFile please select an editor for the root part
  3296.     StandardFileReply sfReply;
  3297.     SFTypeList sfTypes;
  3298.     sfTypes[0] = 'shlb';
  3299.     sfTypes[1] = 'shlb';
  3300.     sfTypes[2] = 'shlb';
  3301.     sfTypes[3] = 'shlb';
  3302.     
  3303.     windowState->DeactivateFrontWindows(ev);
  3304.     StandardGetFile((FileFilterUPP)kODNULL,1,sfTypes,&sfReply);
  3305.     windowState->ActivateFrontWindows(ev);
  3306.     
  3307.     if (sfReply.sfGood) 
  3308.     {
  3309.         ODPart* embeddedPart;
  3310.         
  3311.         ODSShort saveResFile = CurResFile();
  3312.         ODSShort resRefNum = FSpOpenResFile(&(sfReply.sfFile),fsRdPerm);
  3313.         EditorSet* theEditorSet = ODGetEditorSetFromResFile(resRefNum);
  3314.         CloseResFile(resRefNum);
  3315.         UseResFile(saveResFile);
  3316.         if (theEditorSet)
  3317.         {
  3318.             EditorSetIterator* itr = theEditorSet->CreateIterator();
  3319.             ODEditor   editor = itr->First();
  3320.             ODDeleteObject( itr );
  3321.             ODDeleteObject( theEditorSet );
  3322.             
  3323.             embeddedPart = su->GetDraft(ev)->CreatePart(ev, kODNULL, editor);
  3324.         embeddedPart->Externalize(ev);
  3325.     
  3326.         TempODTransform externalXForm = frame->CreateTransform(ev);
  3327.         ODSLong count = 1 + _fContents->Count();
  3328.     
  3329.         Point ptTemp;
  3330.         SetPt(&ptTemp,(short)(count*20),(short)(count*20));
  3331.         externalXForm->SetQDOffset(ev, &ptTemp);
  3332.         TempODFrame embeddedFrame = somSelf->MakeEmbeddedFrame(ev, frame,
  3333.                                                    kODNULL,
  3334.                                                    externalXForm,
  3335.                                                    embeddedPart,
  3336.                                                    kODFalse);
  3337.                                                
  3338.         ODFrameFacetIterator* facets = frame->CreateFacetIterator(ev);
  3339.         for (ODFacet* facet = facets->First(ev); facets->IsNotComplete(ev);
  3340.                 facet = facets->Next(ev))
  3341.         {
  3342.             TempODShape frameShape = embeddedFrame->AcquireFrameShape(ev, kODNULL);
  3343.             TempODShape clip = frameShape->Copy(ev);
  3344.             TempODTransform xform = somSelf->ProxyForFrame(ev, embeddedFrame)->transform->Copy(ev);
  3345.             facet->CreateEmbeddedFacet(ev, embeddedFrame, clip, xform,
  3346.                                         kODNULL, kODNULL, kODNULL, kODFrameInFront);
  3347.         }
  3348.         delete facets;
  3349.         somSelf->ClipEmbeddedFrames(ev, frame);
  3350.         frame->Invalidate(ev, kODNULL, kODNULL);
  3351.         
  3352.         if (newPart)
  3353.             *newPart = embeddedPart;
  3354.         else
  3355.             ODReleaseObject(ev,embeddedPart);
  3356.         }
  3357.     }
  3358.  
  3359.     SOM_CATCH_ALL_ENDTRY
  3360. }
  3361.                     
  3362.                 
  3363.             
  3364.  
  3365.  
  3366. SOM_Scope void  SOMLINK AppleTest_ContainerSetGrafPortOrigin(AppleTest_Container *somSelf, Environment *ev,
  3367.         ODFacet* facet)
  3368. {
  3369.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  3370.     AppleTest_ContainerMethodDebug("AppleTest_Container","SetGrafPortOrigin");
  3371.  
  3372.     SOM_TRY
  3373.     
  3374.     TempODTransform localToGlobal = facet->AcquireContentTransform(ev, kODNULL);
  3375.     ODPoint offset(0,0);
  3376.     localToGlobal->TransformPoint(ev, &offset);
  3377.     SetOrigin(-offset.IntX(), -offset.IntY());
  3378.  
  3379.     SOM_CATCH_ALL_ENDTRY
  3380. }
  3381.  
  3382. SOM_Scope void  SOMLINK AppleTest_ContainerInvalEmbedFrameAfterResize(AppleTest_Container *somSelf, Environment *ev,
  3383.         ODFacet* facet,
  3384.         Proxy* selection,
  3385.         ODShape* oldShape,
  3386.         ODShape* newShape,
  3387.         Point* transOffset)
  3388. {
  3389.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  3390.     AppleTest_ContainerMethodDebug("AppleTest_Container","InvalEmbedFrameAfterResize");
  3391.  
  3392.     SOM_TRY
  3393.     
  3394.     // invalidate old frame shape
  3395.     TempODShape oldShapeCopy = oldShape->Copy(ev);
  3396.     oldShapeCopy->Transform(ev, selection->transform);
  3397.     facet->GetFrame(ev)->Invalidate(ev, oldShapeCopy, kODNULL);
  3398.  
  3399.     TempODShape newShapeCopy = newShape->Copy(ev);        // save to invalidate later
  3400.  
  3401.     selection->frame->ChangeFrameShape(ev, newShape, kODNULL);    // already in frame coords
  3402.  
  3403.     // if the left or top side of the frame was adjusted, the transform will be updated
  3404.     if ((transOffset->h != 0) || (transOffset->v != 0))
  3405.     {
  3406.         ODPoint ODtransOffset (*transOffset);
  3407.         selection->transform->MoveBy(ev, &ODtransOffset);
  3408.  
  3409.         // $$$$$ move facets for selected frame - this is slightly hackish
  3410.         ODFacetIterator* facets =
  3411.             facet->GetWindow(ev)->GetRootFacet(ev)->CreateFacetIterator(ev, kODTopDown, kODFrontToBack);
  3412.         for (ODFacet* child = facets->First(ev);
  3413.                 facets->IsNotComplete(ev); child = facets->Next(ev))
  3414.         {
  3415.             if (child->GetFrame(ev) == selection->frame)
  3416.             {
  3417.                 TempODTransform newTrans = selection->transform->Copy(ev);
  3418.                 child->ChangeGeometry(ev, kODNULL, newTrans, kODNULL);
  3419.                 facets->SkipChildren(ev);
  3420.             }
  3421.         }
  3422.         delete facets;
  3423.     }
  3424.  
  3425.     // invalidate changed areas
  3426.     newShapeCopy->Transform(ev, selection->transform);
  3427.     facet->GetFrame(ev)->Invalidate(ev, newShapeCopy, kODNULL);
  3428.  
  3429.     somSelf->InvalidateSelection(ev, facet->GetFrame(ev));
  3430.     somSelf->UpdateProxyRegion(ev, selection);
  3431.     somSelf->CreateProxySelectionBorder(ev, selection);
  3432.     somSelf->ClipEmbeddedFrames(ev, facet->GetFrame(ev));
  3433.     somSelf->InvalidateSelection(ev, facet->GetFrame(ev));
  3434.     
  3435.     // DMc: Changing presentation is an "incidental" state change that should not
  3436.     // force the document to becoe dirty; do not call SetChangedFromPrev().
  3437.     // somSelf->GetStorageUnit(ev)->GetDraft(ev)->SetChangedFromPrev(ev);
  3438.  
  3439.     SOM_CATCH_ALL_ENDTRY
  3440. }
  3441.  
  3442.  
  3443. SOM_Scope Rect*  SOMLINK AppleTest_ContainerGetSelectionRectLocal(AppleTest_Container *somSelf, Environment *ev,
  3444.         Proxy* selection)
  3445. {
  3446.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  3447.     AppleTest_ContainerMethodDebug("AppleTest_Container","GetSelectionRectLocal");
  3448.  
  3449.     SOM_TRY
  3450.     
  3451.     TempODShape frameShape = selection->frame->AcquireFrameShape(ev, kODNULL);
  3452.     RgnHandle shapeRgn = frameShape->GetQDRegion(ev);
  3453.     Rect shapeRect = (**shapeRgn).rgnBBox;
  3454.     
  3455.     Rect* localRect = new Rect;
  3456.     SetRect(localRect, shapeRect.left, shapeRect.top,
  3457.                         shapeRect.right, shapeRect.bottom);
  3458.     
  3459.     Point offset = selection->transform->GetQDOffset(ev);
  3460.     OffsetRect(localRect, offset.h, offset.v);
  3461.     
  3462.     return localRect;
  3463.  
  3464.     SOM_CATCH_ALL_ENDTRY
  3465.     return kODNULL;
  3466. }
  3467.  
  3468. SOM_Scope void  SOMLINK AppleTest_ContainerCreatePalette(AppleTest_Container *somSelf, Environment *ev)
  3469. {
  3470.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  3471.     AppleTest_ContainerMethodDebug("AppleTest_Container","CreatePalette");
  3472.  
  3473.     SOM_TRY
  3474.     
  3475.     if (_fPalette == kODNULL) {
  3476.         ODPlatformWindow    platformWindow;
  3477.         Rect                windRect;
  3478.         
  3479.         SetRect(&windRect, kPaletteLeft, kPaletteTop, kPaletteRight, kPaletteBottom);
  3480.         platformWindow = NewCWindow(kODNULL,
  3481.                                     &windRect,
  3482.                                     "\p",
  3483.                                     false,
  3484.                                     noGrowDocProc,
  3485.                                     (WindowPtr)-1L,
  3486.                                     true,
  3487.                                     kODNULL);
  3488.         MoveWindow(platformWindow, 100, 100, kODFalse);
  3489.         _fPalette = somSelf->GetStorageUnit(ev)->GetSession(ev)->GetWindowState(ev)->
  3490.                     RegisterWindow(ev, platformWindow,
  3491.                                      kODFrameObject,
  3492.                                      kODFalse,
  3493.                                      kODFalse,    // Is resizable
  3494.                                      kODTrue,    // Is floating
  3495.                                      kODFalse,    // don't save
  3496.                                      kODTrue,             // should dispose
  3497.                                      _fPartWrapper, 
  3498.                                      _fSession->Tokenize(ev, kODViewAsFrame),
  3499.                                      _fSession->Tokenize(ev, kDrawPresPalette),
  3500.                                      kODNULL);
  3501.         _fPalette->Open(ev);
  3502.     }
  3503.  
  3504.     SOM_CATCH_ALL_ENDTRY
  3505. }
  3506.  
  3507. SOM_Scope void  SOMLINK AppleTest_ContainerDestroyPalette(AppleTest_Container *somSelf, Environment *ev)
  3508. {
  3509.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  3510.     AppleTest_ContainerMethodDebug("AppleTest_Container","DestroyPalette");
  3511.  
  3512.     SOM_TRY
  3513.     
  3514.     if (_fPalette != kODNULL) {
  3515.         _fPalette->CloseAndRemove(ev);
  3516.         _fPalette = kODNULL;
  3517.     }
  3518.  
  3519.     SOM_CATCH_ALL_ENDTRY
  3520. }
  3521.  
  3522. SOM_Scope void  SOMLINK AppleTest_ContainerShowPalette(AppleTest_Container *somSelf, Environment *ev)
  3523. {
  3524.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  3525.     AppleTest_ContainerMethodDebug("AppleTest_Container","ShowPalette");
  3526.  
  3527.     SOM_TRY
  3528.     
  3529.     if (_fPaletteUp != kODFalse) {
  3530.         if (_fPalette == kODNULL)
  3531.             somSelf->CreatePalette(ev);
  3532.         _fPalette->Show(ev);
  3533.     }
  3534.  
  3535.     SOM_CATCH_ALL_ENDTRY
  3536. }
  3537.  
  3538. SOM_Scope void  SOMLINK AppleTest_ContainerHidePalette(AppleTest_Container *somSelf, Environment *ev)
  3539. {
  3540.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  3541.     AppleTest_ContainerMethodDebug("AppleTest_Container","HidePalette");
  3542.  
  3543.     SOM_TRY
  3544.     
  3545.     if (_fPalette != kODNULL) {
  3546.         _fPalette->Hide(ev);
  3547.     }
  3548.  
  3549.     SOM_CATCH_ALL_ENDTRY
  3550. }
  3551.  
  3552. SOM_Scope void  SOMLINK AppleTest_ContainerGetBGColor(AppleTest_Container *somSelf, Environment *ev,
  3553.         ODUShort whichColor,
  3554.         RGBColor* newColor)
  3555. {
  3556.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  3557.     AppleTest_ContainerMethodDebug("AppleTest_Container","GetBGColor");
  3558.  
  3559.     SOM_TRY
  3560.     
  3561.     switch (whichColor)
  3562.     {
  3563.         case  kGray: *newColor = rgbGray;        break;
  3564.         case  kRed: *newColor = rgbRed;        break;
  3565.         case  kGreen: *newColor = rgbGreen;        break;
  3566.         case  kYellow: *newColor = rgbYellow;    break;
  3567.         case  kBlue: *newColor = rgbBlue;        break;
  3568.         case  kMagenta: *newColor = rgbMagenta;    break;
  3569.         case  kCyan: *newColor = rgbCyan;        break;
  3570.         case  kWhite: *newColor = rgbWhite;        break;
  3571.         
  3572.         default:
  3573.             WASSERTM(kODFalse, "No such color.");
  3574.             break;
  3575.     }
  3576.  
  3577.     SOM_CATCH_ALL_ENDTRY
  3578. }
  3579.  
  3580.  
  3581. SOM_Scope ODFrame*  SOMLINK AppleTest_ContainerMakeEmbeddedFrame(AppleTest_Container *somSelf, Environment *ev,
  3582.         ODFrame* containingFrame,
  3583.         ODShape* frameShape,
  3584.         ODTransform* externalTransform,
  3585.         ODPart* embedPart,
  3586.         ODBoolean isOverlaid)
  3587. {
  3588.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  3589.     AppleTest_ContainerMethodDebug("AppleTest_Container","MakeEmbeddedFrame");
  3590.  
  3591.     SOM_TRY
  3592.     
  3593.     TempODShape newShape = NULL;
  3594.  
  3595.     // decide what newShape should be - for now, give it what it asked for
  3596.     if (frameShape)
  3597.     {    
  3598.         newShape = frameShape;
  3599.         newShape ->Acquire(ev);
  3600.     }
  3601.     else
  3602.     {    // no frameShape specified, use a default size
  3603.         ODRect rect;
  3604.         rect.SetInt(0,0,80,80);
  3605.         newShape = containingFrame->CreateShape(ev);
  3606.         newShape->SetRectangle(ev, &rect);
  3607.     }
  3608.     
  3609.     // create the new frame
  3610.     // kODNullTypeToken
  3611.     ODFrame* newFrame = somSelf->GetStorageUnit(ev)->GetDraft(ev)->
  3612.             CreateFrame(ev, kODFrameObject, containingFrame, newShape, (ODCanvas*)kODNULL,
  3613.                         embedPart, _fSession->Tokenize(ev, kODViewAsFrame), _fSession->Tokenize(ev, kODPresDefault),
  3614.                         kODFalse, isOverlaid);
  3615.  
  3616.     somSelf->CreateFrameProxy(ev, newFrame, externalTransform);
  3617.  
  3618.     return newFrame;
  3619.  
  3620.     SOM_CATCH_ALL_ENDTRY
  3621.     return kODNULL;
  3622. }
  3623.  
  3624. SOM_Scope ODWindow*  SOMLINK AppleTest_ContainerCreateWindow(AppleTest_Container *somSelf, Environment *ev,
  3625.         ODFrame* sourceFrame)
  3626. {
  3627.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  3628.     AppleTest_ContainerMethodDebug("AppleTest_Container","CreateWindow");
  3629.  
  3630.     SOM_TRY
  3631.     
  3632.     Rect windRect;
  3633.     ODPlatformWindow platformWindow = kODNULL;
  3634.     ODWindow* window = kODNULL;
  3635.     
  3636.     if (sourceFrame)
  3637.     {
  3638.         SetRect(&windRect, 100, 100, 300, 300);    
  3639.     }
  3640.     else
  3641.     {
  3642.         const    ODSShort        kOnePageWidth = 600;
  3643.         // Get the menu bar height, for figuring the top of our windows
  3644.         ODSShort    mbHeight    = 24; //(*(ODSShort*)MBarHeight);    //get it from lomem
  3645.         SetRect(&windRect, 4, mbHeight+16,
  3646.                 ODQDGlobals.screenBits.bounds.right - 64,
  3647.                 ODQDGlobals.screenBits.bounds.bottom - 4);        
  3648.         
  3649.         if (windRect.right-windRect.left > kOnePageWidth)
  3650.         {
  3651.             windRect.right = windRect.left + kOnePageWidth;
  3652.         }
  3653.     }
  3654.  
  3655.     ODName* windowName = kODNULL;
  3656.     Str255  pWindowName;
  3657.     if (sourceFrame)
  3658.         windowName = ODGetPartName(ev, sourceFrame, kODNULL);
  3659.     if (windowName==kODNULL || GetITextStringLength(windowName)==0)
  3660.         CopyPascalString(pWindowName, "\pContainer");
  3661.     else
  3662.         GetITextPString(windowName, pWindowName);
  3663.         
  3664.     if (windowName)
  3665.         DisposeIText(windowName);
  3666.     
  3667.     platformWindow = NewCWindow(kODNULL, &windRect, pWindowName, false, zoomDocProc, (WindowPtr)-1L, true, kODNULL);
  3668.     window =  _fSession->GetWindowState(ev)->RegisterWindow(ev, platformWindow, 
  3669.                                                     kODFrameObject,
  3670.                                                      (sourceFrame==kODNULL),    // Keeps draft open
  3671.                                                      kODTrue,    // Is resizable
  3672.                                                      kODFalse,    // Is floating
  3673.                                                      kODTrue,  // should save
  3674.                                                      kODTrue,  // should dispose
  3675.                                                     _fPartWrapper,
  3676.                                                     _fSession->Tokenize(ev, kODViewAsFrame),
  3677.                                                     _fSession->Tokenize(ev, kDrawPresNormal),
  3678.                                                     sourceFrame);
  3679.  
  3680.     return window;
  3681.  
  3682.     SOM_CATCH_ALL_ENDTRY
  3683.     return kODNULL;
  3684. }
  3685.  
  3686. SOM_Scope void  SOMLINK AppleTest_ContainersomInit(AppleTest_Container *somSelf)
  3687. {
  3688.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  3689.     AppleTest_ContainerMethodDebug("DrawPart","somInit");
  3690.  
  3691.     parent_somInit(somSelf);
  3692.  
  3693.     gSession = kODNULL;
  3694.  
  3695.     _fDisplayFrames = kODNULL;
  3696.     _fEmbeddedFrames = kODNULL;
  3697.     _fWindowID = 0;
  3698.  
  3699.     _fFrameGroupIDCounter = 1;
  3700.  
  3701.     _fContents = kODNULL;
  3702.     _fSelection = kODNULL;
  3703.  
  3704.     _fSelectRgn = kODNULL;
  3705.     _fCornerHandleRgn = kODNULL;
  3706.     _fEdgeHandleRgn = kODNULL;
  3707.  
  3708.     _fColorMenu = kODNULL;
  3709.     _fEmbedMenu = kODNULL;
  3710.     _fFrameMenu = kODNULL;
  3711.     _fScriptingMenu = kODNULL;
  3712.     _fMenuBar = kODNULL;
  3713.     _fFocusSet = kODNULL;
  3714.  
  3715.     _fSemtIntf = kODNULL;
  3716.     _fTestDrawSU = kODNULL;
  3717.     
  3718.     _fPalette = kODNULL;
  3719.     _fPaletteUp = kODFalse;
  3720.     _fPaletteWasShown = kODFalse;
  3721.     _fScriptingOn = kODTrue;
  3722.     
  3723.     _fLargeIcons = kODNULL;
  3724.     _fSmallIcons = kODNULL;
  3725.  
  3726.     _fSession = kODNULL;
  3727.     
  3728.     _fPrintRecord = kODNULL;
  3729.     _fPartWrapper = kODNULL;
  3730.     _fDrawingLines = kODFalse;
  3731. }
  3732.  
  3733. SOM_Scope void  SOMLINK AppleTest_ContainersomUninit(AppleTest_Container *somSelf)
  3734. {
  3735.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  3736.     AppleTest_ContainerMethodDebug("DrawPart","somUninit");
  3737.  
  3738.     if (_fContents != kODNULL)
  3739.         delete _fContents;
  3740.     if (_fSelection != kODNULL)
  3741.         delete _fSelection;
  3742.     if (_fSelectRgn) ODDisposeHandle((Handle)_fSelectRgn);
  3743.     if (_fCornerHandleRgn) ODDisposeHandle((Handle)_fCornerHandleRgn);
  3744.     if (_fEdgeHandleRgn) ODDisposeHandle((Handle)_fEdgeHandleRgn);
  3745.     
  3746.     Environment* ev = somGetGlobalEnvironment();
  3747.  
  3748.     if (_fMenuBar != kODNULL) {    
  3749.         _fMenuBar->UnregisterCommand(ev, cGray);
  3750.         _fMenuBar->UnregisterCommand(ev, cRed);
  3751.         _fMenuBar->UnregisterCommand(ev, cGreen);
  3752.         _fMenuBar->UnregisterCommand(ev, cYellow);
  3753.         _fMenuBar->UnregisterCommand(ev, cBlue);
  3754.         _fMenuBar->UnregisterCommand(ev, cMagenta);
  3755.         _fMenuBar->UnregisterCommand(ev, cCyan);
  3756.         _fMenuBar->UnregisterCommand(ev, cWhite);
  3757.         _fMenuBar->UnregisterCommand(ev, cOtherColor);
  3758.         
  3759.         _fMenuBar->RemoveMenu(ev, kDrawColorMenuID);
  3760.         _fMenuBar->RemoveMenu(ev, kDrawEmbedMenuID);
  3761. #ifndef BETASEEDMODS
  3762.         _fMenuBar->RemoveMenu(ev, kDrawFrameMenuID);
  3763. #endif
  3764.  
  3765. #ifdef SCRIPTDEBUG
  3766.     _fMenuBar->UnregisterCommand(ev, cToggleScripting);
  3767.     _fMenuBar->RemoveMenu(ev, kDrawScriptingMenuID);
  3768. #endif
  3769.         
  3770.         _fMenuBar->Release(ev);
  3771.     }
  3772.     
  3773.     if (_fFocusSet) delete _fFocusSet;
  3774.     
  3775.     if (_fColorMenu) DisposeMenu(_fColorMenu);
  3776.     if (_fEmbedMenu) DisposeMenu(_fEmbedMenu);
  3777. #ifndef BETASEEDMODS
  3778.     if (_fFrameMenu) DisposeMenu(_fFrameMenu);
  3779. #endif
  3780.  
  3781. #ifdef SCRIPTDEBUG
  3782.     if (_fScriptingMenu) DisposeMenu(_fScriptingMenu);
  3783. #endif
  3784.  
  3785.     if (_fDisplayFrames != kODNULL)
  3786.         delete _fDisplayFrames;        // make sure it's empty first
  3787.     if (_fEmbeddedFrames != kODNULL)
  3788.         delete _fEmbeddedFrames;        // make sure it's empty first
  3789.  
  3790.     ODReleaseObject(ev,_fTestDrawSU);
  3791.     parent_somUninit(somSelf);
  3792. }
  3793.  
  3794. SOM_Scope void  SOMLINK AppleTest_ContainerFulfillPromise(AppleTest_Container *somSelf, Environment *ev,
  3795.         ODStorageUnitView* promiseSUView)
  3796. {
  3797.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  3798.     AppleTest_ContainerMethodDebug("AppleTest_Container","FulfillPromise");
  3799.  
  3800.     SOM_TRY
  3801.     
  3802.     TempODPropertyName property = promiseSUView->GetProperty(ev);
  3803.  
  3804.     if ( ODISOStrEqual(property, kPropFrameInfo) ) {
  3805.         Proxy* selection = kODNULL;
  3806.  
  3807.         // Just to test whether GetPromiseValue works
  3808.         {
  3809.             const ODULong kBufferSize = 255;
  3810.             ODPart* part = kODNULL;
  3811.             ODByteArray ba;
  3812.             ODULong length = promiseSUView->GetPromiseValue(ev, kDrawFrameID, 0, kBufferSize, &ba, &part);
  3813.             if ((length != sizeof(ODID)) || (part != _fPartWrapper)) {
  3814.                 WARN("GetPromiseValue fails!");
  3815.             }
  3816.             ODDisposePtr(ba._buffer);
  3817.         }
  3818.             
  3819.         ODULong size = promiseSUView->GetSize(ev);
  3820.         ASSERTM(size == sizeof(Proxy*), kODErrAssertionFailed, "Invalid Proxy");
  3821.         if (size != sizeof(Proxy*)) {
  3822.             promiseSUView->DeleteValue(ev, size);
  3823.         }
  3824.         else {
  3825.             StorageUnitViewGetValue(promiseSUView, ev, sizeof(Proxy*), &selection);
  3826.             promiseSUView->SetOffset(ev, 0);
  3827.             ODID frameInfoData = selection->frame->GetID(ev);
  3828.             StorageUnitViewSetValue(promiseSUView, ev, sizeof(ODID), (ODValue) &frameInfoData);
  3829.         }
  3830.     }
  3831.     else if ( ODISOStrEqual(property, kODPropMouseDownOffset) ) {
  3832.         // The promise data is also the correct value
  3833.         // $$$$$ Is it mandatory that the promise be replaced by SetValue???
  3834.         ODULong size = promiseSUView->GetSize(ev);
  3835.         ASSERTM(size == sizeof(Point), kODErrAssertionFailed, "Invalid Point");
  3836.         Point mdOffset;
  3837.         StorageUnitViewGetValue(promiseSUView, ev, sizeof(Point), (ODValue) &mdOffset);
  3838.         promiseSUView->SetOffset(ev, 0);
  3839.         StorageUnitViewSetValue(promiseSUView, ev, sizeof(Point), (ODValue) &mdOffset);
  3840.     }
  3841.     else if ( ODISOStrEqual(property, kODPropContents) ) {
  3842.         
  3843. #if ODDebug
  3844.         somPrintf("Draw %d::FulfillPromise: Fulfilling promised content\n", somSelf->GetID(ev));
  3845. #endif
  3846.         // Clone this part's content
  3847.         ODStorageUnit*    toSU = promiseSUView->GetStorageUnit(ev);
  3848.         ODDraft*        toDraft = promiseSUView->GetStorageUnit(ev)->GetDraft(ev);
  3849.         ODDraft*        fromDraft = somSelf->GetStorageUnit(ev)->GetDraft(ev);
  3850.         ODStorageUnit*    testDrawContentSU = toDraft->CreateStorageUnit(ev);
  3851.         ODDraftKey        key = 0;
  3852.         ODID            toID = 0;
  3853.         ODFrame*        scopeFrame = kODNULL;    // $$$$$ should come from promise value
  3854.         TRY
  3855.             key = fromDraft->BeginClone(ev, toDraft, kODNULL, kODCloneCut);    // $$$$$ is cut vs. copy significant???
  3856.             somSelf->CloneTestDrawContent(ev, key, testDrawContentSU, scopeFrame);
  3857.             fromDraft->EndClone(ev, key);
  3858.         CATCH_ALL
  3859.             WARN("Clone Problem in DrawPartFulfillPromise.");
  3860.             if (key != 0)
  3861.                 fromDraft->AbortClone(ev, key);
  3862.             RERAISE;
  3863.         ENDTRY
  3864.         
  3865.         // Replace the promise with a reference to the cloned storage unit
  3866.         ODStorageUnitRef aSURef;
  3867.         promiseSUView->GetStrongStorageUnitRef(ev, testDrawContentSU->GetID(ev), aSURef);
  3868.         promiseSUView->SetOffset(ev, 0);
  3869.         StorageUnitViewSetValue(promiseSUView, ev, sizeof(ODStorageUnitRef), (ODValue)&aSURef);
  3870.     }
  3871.  
  3872. #if ODDebug
  3873.     somPrintf("Draw %d::FulfillPromise: Complete\n", somSelf->GetID(ev));
  3874. #endif
  3875.  
  3876.     SOM_CATCH_ALL_ENDTRY
  3877. }
  3878.  
  3879. SOM_Scope void  SOMLINK AppleTest_ContainerDropCompleted(AppleTest_Container *somSelf, Environment *ev,
  3880.         ODPart* destPart,
  3881.         ODDropResult dropResult)
  3882. {
  3883.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  3884.     AppleTest_ContainerMethodDebug("AppleTest_Container","DropCompleted");
  3885.  
  3886.     SOM_TRY
  3887.     
  3888.     ODUnused(destPart);
  3889.     ODUnused(dropResult);
  3890. //    parent_DropCompleted(somSelf,ev,destPart,dropResult);
  3891.  
  3892.     SOM_CATCH_ALL_ENDTRY
  3893. }
  3894.  
  3895. SOM_Scope ODDragResult  SOMLINK AppleTest_ContainerDragEnter(AppleTest_Container *somSelf, Environment *ev,
  3896.         ODDragItemIterator* dragInfo,
  3897.         ODFacet* facet,
  3898.         ODPoint* where)
  3899. {
  3900.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  3901.     AppleTest_ContainerMethodDebug("AppleTest_Container","DragEnter");
  3902.  
  3903.     SOM_TRY
  3904.     
  3905.     ODUnused(dragInfo);
  3906.     ODUnused(where);
  3907.  
  3908.     ShowMyDragHilite(ev, _fSession->GetDragAndDrop(ev), facet);
  3909.     
  3910.     return kODTrue;
  3911.  
  3912.     SOM_CATCH_ALL_ENDTRY
  3913.     return kODFalse;
  3914. }
  3915.  
  3916. SOM_Scope ODDragResult  SOMLINK AppleTest_ContainerDragWithin(AppleTest_Container *somSelf, Environment *ev,
  3917.         ODDragItemIterator* dragInfo,
  3918.         ODFacet* facet,
  3919.         ODPoint* where)
  3920. {
  3921.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  3922.     AppleTest_ContainerMethodDebug("AppleTest_Container","DragWithin");
  3923.  
  3924.     SOM_TRY
  3925.     
  3926.     ODUnused(dragInfo);
  3927.     ODUnused(facet);
  3928.     ODUnused(where);
  3929.     
  3930.     ShowMyDragHilite(ev, _fSession->GetDragAndDrop(ev), facet);
  3931.     
  3932.     return kODTrue;
  3933.  
  3934.     SOM_CATCH_ALL_ENDTRY
  3935.     return kODFalse;
  3936. }
  3937.  
  3938. SOM_Scope void  SOMLINK AppleTest_ContainerDragLeave(AppleTest_Container *somSelf, Environment *ev,
  3939.         ODFacet* facet,
  3940.         ODPoint* where)
  3941. {
  3942.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  3943.     AppleTest_ContainerMethodDebug("AppleTest_Container","DragLeave");
  3944.  
  3945.     SOM_TRY
  3946.     
  3947.     ODUnused(where);
  3948.     
  3949.     HideMyDragHilite(ev, _fSession->GetDragAndDrop(ev), facet);
  3950.  
  3951.  
  3952.     SOM_CATCH_ALL_ENDTRY
  3953. }
  3954.  
  3955. SOM_Scope ODDropResult  SOMLINK AppleTest_ContainerDrop(AppleTest_Container *somSelf, Environment *ev,
  3956.         ODDragItemIterator* dropInfo,
  3957.         ODFacet* facet,
  3958.         ODPoint* where)
  3959. {
  3960.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  3961.     AppleTest_ContainerMethodDebug("AppleTest_Container","Drop");
  3962.  
  3963.     SOM_TRY
  3964.     
  3965.     ODDraft       *theDraft = somSelf->GetStorageUnit(ev)->GetDraft(ev);
  3966.     ODULong        attributes;
  3967.     Point           delta, dragPoint, dropPoint, pinnedPoint, newXTrans;
  3968. //    short           mouseDownModifiers, mouseUpModifiers;
  3969.     ODStorageUnit *dropSU = kODNULL;
  3970.     ODStorageUnit *newSU = kODNULL;
  3971.     ODID        draggedFrameID;
  3972.     Proxy        *p = kODNULL;
  3973.     ODFrame        *frameDroppedIn;
  3974.     TempODFrame newFrame = kODNULL; // DMc refcount - make temp
  3975.     ODPart        *newPart = kODNULL;
  3976.     ODShape        *clipShape = kODNULL;
  3977.     ODShape        *newFrameShape = kODNULL;
  3978.     
  3979.     ODDropResult    dropResult = kODDropMove;
  3980.  
  3981.     HideMyDragHilite(ev, _fSession->GetDragAndDrop(ev), facet);
  3982.     
  3983.     // Get the attributes and other crap for this drag
  3984.     attributes = _fSession->GetDragAndDrop(ev)->GetDragAttributes(ev);
  3985.         
  3986.     for (dropSU = dropInfo->First(ev); dropSU;
  3987.             dropSU = dropInfo->Next(ev))
  3988.     {        
  3989.         if ((attributes & kODDropIsInSourceFrame) && (attributes & kODDropIsMove))
  3990.         {
  3991.             // Get where drag started and tweak our own structures to do the move.
  3992.             DragReference   theDrag = _fSession->GetDragAndDrop(ev)->GetDragReference(ev);
  3993.             GetDragOrigin(theDrag, &dragPoint);
  3994.             GetDragMouse(theDrag, &dropPoint, &pinnedPoint);
  3995.             delta.h = dropPoint.h - dragPoint.h;
  3996.             delta.v = dropPoint.v - dragPoint.v;
  3997.             dropSU->Focus(ev, kPropFrameInfo, kODPosUndefined, kDrawFrameID, 0, kODPosFirstSib);
  3998.             StorageUnitGetValue(dropSU, ev, sizeof(ODID), (ODValue) &draggedFrameID);
  3999.             p = somSelf->ProxyForFrameID(ev, draggedFrameID);
  4000.             
  4001.             // $$$$$ this is a single-facet hack
  4002.             ODPoint ODDelta (delta);
  4003.             p->transform->MoveBy(ev, &ODDelta);
  4004.             TempODTransform newExternalXForm = p->transform->Copy(ev);
  4005.             ODFrameFacetIterator* facets = p->frame->CreateFacetIterator(ev);
  4006.             facets->First(ev)->ChangeGeometry(ev, kODNULL, newExternalXForm, kODNULL);
  4007.             delete facets;
  4008.             
  4009.             somSelf->UpdateProxyRegion(ev, p);
  4010.             somSelf->CreateProxySelectionBorder(ev, p);
  4011.             
  4012.             dropResult = kODDropMove;
  4013.         }
  4014.         else
  4015.         {
  4016.             ODDraft*    fromDraft = dropSU->GetDraft(ev);
  4017.             ODDraftKey    key;
  4018.             ODID        newPartID;
  4019.             ODID        newFrameID = 0;
  4020.             ODCloneKind    cloneKind;
  4021.             if (attributes & kODDropIsMove) {
  4022.                 cloneKind = kODCloneDropMove;
  4023.                 dropResult = kODDropMove;
  4024.             }
  4025.             else {
  4026.                 cloneKind = kODCloneDropCopy;
  4027.                 dropResult = kODDropCopy;
  4028.             }
  4029.             
  4030.             ODVolatile(fromDraft);
  4031.             ODVolatile(key);
  4032.             
  4033. #if defined(ODDebug) && ODDebugDrags
  4034.             somPrintf("Draw::Drop: Cloning root su\n");
  4035. #endif
  4036.             TRY
  4037.                 key = fromDraft->BeginClone(ev, theDraft, facet->GetFrame(ev), cloneKind);
  4038.                 newPartID = fromDraft->Clone(ev, key, dropSU->GetID(ev), 0, 0);
  4039.                 ODID oldPartID = ODGetWeakSURefProp(ev, dropSU, kODPropContentFrame, kODWeakStorageUnitRef);
  4040.                 if (oldPartID != 0)
  4041.                 {
  4042.                     newFrameID = fromDraft->Clone(ev, key, oldPartID, 0, 0);                
  4043.                 }
  4044.                 fromDraft->EndClone(ev, key);
  4045.             CATCH_ALL
  4046.                 fromDraft->AbortClone(ev, key);
  4047.                 RERAISE;
  4048.             ENDTRY
  4049.             
  4050.             // Get the mouse down offset from the drop storage unit
  4051.             if (ODSUExistsThenFocus(ev, dropSU, kODPropMouseDownOffset, kQDPoint))
  4052.             {
  4053.                 Point mdOffset = {0,0};
  4054.                 newXTrans = where->AsQDPoint();
  4055.                 
  4056.                 // $$$$$ SHOULD USE STDTYPIO FOR STANDARD TYPES LIKE POINTS!
  4057.                 StorageUnitGetValue(dropSU, ev, sizeof(Point), (ODValue) &mdOffset);
  4058.                 
  4059.                 SubPt(mdOffset,&newXTrans);
  4060.             }
  4061.             else
  4062.             {
  4063.                 newXTrans = where->AsQDPoint();
  4064.             }
  4065.             
  4066.             TempODTransform extXForm = facet->CreateTransform(ev);
  4067.             extXForm->SetQDOffset(ev, &newXTrans);
  4068.             
  4069.             newPart = theDraft->AcquirePart(ev, newPartID);
  4070.  
  4071.             frameDroppedIn = facet->GetFrame(ev);
  4072.             
  4073.             if ( newFrameID == 0 )
  4074.             {
  4075.                 if (ODSUExistsThenFocus(ev, dropSU, kODPropSuggestedFrameShape, kODNULL))
  4076.                 {
  4077.                     newFrameShape = facet->CreateShape(ev);
  4078.                     newFrameShape->ReadShape(ev, dropSU);
  4079.                 }
  4080.  
  4081.                 newFrame = somSelf->MakeEmbeddedFrame(ev, frameDroppedIn,
  4082.                         newFrameShape, extXForm, newPart, kODFalse);
  4083.  
  4084. #if defined(ODDebug) && ODDebugDrags
  4085.                 somPrintf("Draw %d::Drop: Embedding new frame %d\n", somSelf->GetID(ev), newFrame->GetID(ev));
  4086. #endif
  4087.  
  4088.                 if (newFrameShape) 
  4089.                 {
  4090.                     newFrameShape->Release(ev);
  4091.                     newFrameShape = kODNULL;
  4092.                 }
  4093.             }
  4094.             else
  4095.             {
  4096. #if defined(ODDebug) && ODDebugDrags
  4097.                 somPrintf("Draw %d::Drop: Embedding cloned frame %d\n", somSelf->GetID(ev), newFrameID);
  4098. #endif
  4099.                 newFrame = theDraft->AcquireFrame(ev, newFrameID); // DMc refcount - use temp
  4100.                 newFrame->SetContainingFrame(ev, frameDroppedIn); 
  4101.                     // Must be before AcquirePart, because then Connected is called, and fNeedsActivating is set
  4102.                 
  4103.                 
  4104.                 { TempODPart tempPart = newFrame->AcquirePart(ev); // DMc refcount - make temp
  4105.                   WASSERTM((newPart == (ODPart*) tempPart), "Draw::Drop - Embedded frame not display frame of embedded part" );
  4106.                 }
  4107.                 newFrame->SetDragging(ev, kODFalse);
  4108.                 newFrame->SetInLimbo(ev, kODFalse);
  4109.                 somSelf->CreateFrameProxy(ev, (ODFrame*) newFrame, extXForm); // DMc refcount - cast temp to ptr
  4110.             }
  4111.             
  4112. #if defined(ODDebug) && ODDebugDrags
  4113.             somPrintf("Draw %d::Drop: Creating facets\n", somSelf->GetID(ev));
  4114. #endif
  4115.             newFrameShape = newFrame->AcquireFrameShape(ev, kODNULL);
  4116.             clipShape = newFrameShape->Copy(ev);
  4117.  
  4118.             TempODTransform copyXForm = somSelf->ProxyForFrame(ev, (ODFrame*) newFrame)->transform->Copy(ev); // DMc refcount - cast temp to ptr
  4119.             ODFacet* newFacet = facet->CreateEmbeddedFacet(ev, (ODFrame*) newFrame, clipShape, copyXForm,
  4120.                                         kODNULL, kODNULL, kODNULL, kODFrameInFront);
  4121.             frameDroppedIn->Invalidate(ev, kODNULL, kODNULL);
  4122.             newPart->Release(ev);
  4123.             newFrameShape->Release(ev); newFrameShape = kODNULL;
  4124.             clipShape->Release(ev); clipShape = kODNULL;
  4125.             
  4126. #if defined(ODDebug) && ODDebugDrags
  4127.             somPrintf("Draw %d::Drop: Activating frame receiving the drop\n", somSelf->GetID(ev));
  4128. #endif
  4129.  
  4130. #if defined(ODDebug) && ODDebugActivates
  4131.         somPrintf("Draw %d::Drop: Calling IsActive\n", somSelf->GetID(ev));
  4132. #endif
  4133.             if (!facet->GetWindow(ev)->IsActive(ev))
  4134.             {
  4135. #if defined(ODDebug) && ODDebugActivates
  4136.         somPrintf("Draw %d::Drop: Calling Select\n", somSelf->GetID(ev));
  4137. #endif
  4138.                 facet->GetWindow(ev)->Select(ev);
  4139.             }
  4140.             //else
  4141.                 somSelf->ActivateFrame(ev, facet->GetFrame(ev));
  4142.                 
  4143. #if defined(ODDebug) && ODDebugDrags
  4144.             somPrintf("Draw %d::Drop: Invalidating and clipping\n", somSelf->GetID(ev));
  4145. #endif
  4146.             ODFrame* selectedFrame = kODNULL;
  4147.             Proxy* p = kODNULL;
  4148.             OrderedCollectionIterator i(_fSelection);
  4149.             p = (Proxy*) i.First();
  4150.             if (p != kODNULL) {
  4151.                 selectedFrame = p->frame;
  4152.                 if (selectedFrame != kODNULL)
  4153.                     somSelf->InvalidateSelection(ev, selectedFrame);
  4154.             }
  4155.             somSelf->EmptySelection(ev);
  4156.             if (selectedFrame)
  4157.                 somSelf->ClipEmbeddedFrames(ev, selectedFrame);
  4158.  
  4159. #if defined(ODDebug) && ODDebugDrags
  4160.             somPrintf("Draw %d::Drop: Hilighting selected frame\n", somSelf->GetID(ev));
  4161. #endif
  4162.             p = somSelf->ProxyForFrame(ev, (ODFrame*) newFrame); // DMc refcount - cast temp to ptr
  4163.             _fSelection->AddFirst((ElementType)p);
  4164.             newFacet->SetSelected(ev, kODTrue);
  4165.             somSelf->CreateProxySelectionBorder(ev, p);
  4166.                     
  4167. #if defined(ODDebug) && ODDebugDrags
  4168.             somPrintf("Draw %d::Drop: Completed; display frames =", somSelf->GetID(ev));
  4169.             OrderedCollectionIterator aIter(_fDisplayFrames);
  4170.             for (ODFrame* aFrame = (ODFrame*)aIter.First(); aIter.IsNotComplete(); aFrame = (ODFrame*)aIter.Next())
  4171.                 somPrintf (" %d", aFrame->GetID(ev));
  4172.             somPrintf ("\n");
  4173.             somPrintf("Draw %d::Drop:            embedded frames =", somSelf->GetID(ev));
  4174.             OrderedCollectionIterator bIter(_fEmbeddedFrames);
  4175.             for (ODFrame* bFrame = (ODFrame*)bIter.First(); bIter.IsNotComplete(); bFrame = (ODFrame*)bIter.Next())
  4176.                 somPrintf (" %d", bFrame->GetID(ev));
  4177.             somPrintf ("\n");
  4178. #endif
  4179.         }
  4180.     }
  4181.     somSelf->GetStorageUnit(ev)->GetDraft(ev)->SetChangedFromPrev(ev);
  4182.     
  4183.     return dropResult;
  4184.  
  4185.     SOM_CATCH_ALL_ENDTRY
  4186.     return kODDropFail;
  4187. }
  4188.  
  4189. SOM_Scope void  SOMLINK AppleTest_ContainerContainingPartPropertiesUpdated(AppleTest_Container *somSelf, Environment *ev,
  4190.         ODFrame* frame,
  4191.         ODStorageUnit* propertyUnit)
  4192. {
  4193.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  4194.     AppleTest_ContainerMethodDebug("AppleTest_Container","ContainingPartPropertiesUpdated");
  4195.  
  4196.     SOM_TRY
  4197.     
  4198.     ODUnused(frame);
  4199.     ODUnused(propertyUnit);
  4200.  
  4201.     SOM_CATCH_ALL_ENDTRY
  4202. }
  4203.  
  4204. SOM_Scope ODStorageUnit*  SOMLINK AppleTest_ContainerAcquireContainingPartProperties(AppleTest_Container *somSelf, Environment *ev,
  4205.         ODFrame* frame)
  4206. {
  4207.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  4208.     AppleTest_ContainerMethodDebug("AppleTest_Container","AcquireContainingPartProperties");
  4209.  
  4210.     SOM_TRY
  4211.     
  4212.     ODUnused(frame);
  4213.  
  4214.     return kODNULL;
  4215.  
  4216.     SOM_CATCH_ALL_ENDTRY
  4217.     return kODNULL;
  4218. }
  4219.  
  4220. SOM_Scope ODBoolean  SOMLINK AppleTest_ContainerRevealFrame(AppleTest_Container *somSelf, Environment *ev,
  4221.         ODFrame* embeddedFrame,
  4222.         ODShape* revealShape)
  4223. {
  4224.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  4225.     AppleTest_ContainerMethodDebug("AppleTest_Container","RevealFrame");
  4226.  
  4227.     SOM_TRY
  4228.     
  4229.     ODUnused(embeddedFrame);
  4230.     ODUnused(revealShape);
  4231.  
  4232.     // $$$$$ THROW(kODErrCannotEmbed);
  4233.     return kODFalse;
  4234.  
  4235.     SOM_CATCH_ALL_ENDTRY
  4236.     return kODFalse;
  4237. }
  4238.  
  4239. SOM_Scope void  SOMLINK AppleTest_ContainerEmbeddedFrameSpec(AppleTest_Container *somSelf, Environment *ev,
  4240.         ODFrame* embeddedFrame,
  4241.         ODObjectSpec* spec)
  4242. {
  4243.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  4244.     AppleTest_ContainerMethodDebug("AppleTest_Container","EmbeddedFrameSpec");
  4245.  
  4246.     SOM_TRY
  4247.     
  4248.     ODUnused(embeddedFrame);
  4249.     ODUnused(spec);
  4250.  
  4251.     THROW(kODErrCannotEmbed);
  4252.  
  4253.     SOM_CATCH_ALL_ENDTRY
  4254. }
  4255.  
  4256. SOM_Scope ODEmbeddedFramesIterator*  SOMLINK AppleTest_ContainerCreateEmbeddedFramesIterator(AppleTest_Container *somSelf, Environment *ev,
  4257.         ODFrame* frame)
  4258. {
  4259.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  4260.     AppleTest_ContainerMethodDebug("AppleTest_Container","CreateEmbeddedFramesIterator");
  4261.  
  4262.     SOM_TRY
  4263.  
  4264.     ODUnused(frame);
  4265.  
  4266.     DrawEmbeddedFramesIterator* iter = new DrawEmbeddedFramesIterator;
  4267.     iter->InitEmbeddedFramesIterator(ev, somSelf);
  4268.     return iter;
  4269.  
  4270.     SOM_CATCH_ALL_ENDTRY
  4271.     return kODNULL;
  4272. }
  4273.  
  4274. SOM_Scope void  SOMLINK AppleTest_ContainerDisplayFrameAdded(AppleTest_Container *somSelf, Environment *ev,
  4275.         ODFrame* frame)
  4276. {
  4277.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  4278.     AppleTest_ContainerMethodDebug("AppleTest_Container","DisplayFrameAdded");
  4279.  
  4280.     SOM_TRY
  4281.  
  4282. #if ODDebug
  4283.     somPrintf("Draw %d::DisplayFrameAdded: Added frame %d\n", somSelf->GetID(ev), frame->GetID(ev));
  4284. #endif
  4285.  
  4286.     TempODPart tempPart = frame->AcquirePart(ev);
  4287.     if (tempPart == _fPartWrapper)        // frame belongs to me
  4288.     {
  4289.         OrderedCollectionIterator    displayFramesIter(_fDisplayFrames);
  4290.         ODFrame* displayFrame = (ODFrame*) displayFramesIter.First();
  4291.         if (displayFramesIter.IsNotComplete() == kODFalse) {
  4292.             OrderedCollectionIterator    contentsIter(_fContents);
  4293.             Proxy*                        proxy;
  4294.             
  4295.             for (proxy = (Proxy*) contentsIter.First();
  4296.                     contentsIter.IsNotComplete(); 
  4297.                     proxy = (Proxy*) contentsIter.Next())
  4298.             {
  4299. #if ODDebug
  4300.                 somPrintf("Draw %d::DisplayFrameAdded: Setting containing frame of embedded frame %d to %d\n", 
  4301.                     somSelf->GetID(ev), proxy->frame->GetID(ev), frame->GetID(ev));
  4302. #endif
  4303.                 proxy->frame->SetContainingFrame(ev, frame);
  4304.             }
  4305.         }
  4306.  
  4307.         // !!! do something with viewType and partInfo...
  4308.         PartInfoRec* pInfo = new PartInfoRec;
  4309.         //pInfo->bgClipRegion = frame->AcquireFrameShape(ev, kODNULL)->CopyQDRegion(ev);            // <12> was GetQDRegion()
  4310.         if (frame->IsRoot(ev))
  4311.         {
  4312.             pInfo->bgColor = rgbWhite;
  4313.             pInfo->fNeedsActivating = kODTrue;
  4314.         } else
  4315.             pInfo->bgColor = _fDefaultColor;
  4316.  
  4317.         frame->SetPartInfo(ev, (ODInfoType) pInfo);
  4318.         _fDisplayFrames->AddLast(frame);
  4319.         frame->Acquire(ev);
  4320.         frame->SetDroppable(ev, kODTrue);
  4321.         
  4322.         if (frame->GetViewType(ev) != _fSession->Tokenize(ev, kODViewAsFrame))                        // if frame view is set don't change it
  4323.             frame->SetViewType(ev, _fSession->Tokenize(ev, kODViewAsFrame));        // if not, make it viewasframe
  4324.         if (frame->GetPresentation(ev) != _fSession->Tokenize(ev, kDrawPresNormal))                    
  4325.             frame->SetPresentation(ev, _fSession->Tokenize(ev, kDrawPresNormal));
  4326.         
  4327.         //if (frame->AcquireContainingFrame(ev) == kODNULL)  // <- watch refcounting
  4328.         //{
  4329.         //    //Wrong place. somSelf->ActivateFrame(ev, frame);
  4330.         //}
  4331.     }
  4332.     else
  4333.         THROW(kODErrInvalidFrame);
  4334.  
  4335.     // render in frame?
  4336.  
  4337.     SOM_CATCH_ALL_ENDTRY
  4338. }
  4339.  
  4340. SOM_Scope void  SOMLINK AppleTest_ContainerAttachSourceFrame(AppleTest_Container *somSelf, Environment *ev,
  4341.         ODFrame* frame,
  4342.         ODFrame* sourceFrame)
  4343. {
  4344.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  4345.     AppleTest_ContainerMethodDebug("AppleTest_Container","AttachSourceFrame");
  4346.  
  4347.     SOM_TRY
  4348.  
  4349.     if (_fDisplayFrames->Contains(frame)
  4350.          && sourceFrame && _fDisplayFrames->Contains(sourceFrame))
  4351.     {
  4352.         //RCR Note. DrawPart does not currently store embedded
  4353.         // frames on a per-containing-frame basis (eg. in the part info
  4354.         // of each frame). Since we can't add to the embedded frames list
  4355.         // while iterating over it, we make a temporary list here
  4356.         
  4357.             OrderedCollection* embeddedFrames = new OrderedCollection;
  4358.             {
  4359.                 OrderedCollectionIterator iter(_fEmbeddedFrames);
  4360.                 for (ODFrame* embeddedFrame = (ODFrame*) iter.First(); 
  4361.                         iter.IsNotComplete(); 
  4362.                         embeddedFrame = (ODFrame*) iter.Next())
  4363.                 {
  4364.                     embeddedFrames->AddLast(embeddedFrame);
  4365.                 }
  4366.             }
  4367.             
  4368.             OrderedCollectionIterator iter(embeddedFrames);
  4369.             for (ODFrame* embeddedFrame = (ODFrame*) iter.First(); 
  4370.                     iter.IsNotComplete(); 
  4371.                     embeddedFrame = (ODFrame*) iter.Next())
  4372.             {
  4373.                 TempODFrame containingFrame = embeddedFrame->AcquireContainingFrame(ev);
  4374.                 if (containingFrame == sourceFrame)
  4375.                 {
  4376.                     TempODPart embeddedPart = embeddedFrame->AcquirePart(ev);
  4377.                     TempODShape frameShape = embeddedFrame->AcquireFrameShape(ev, kODNULL);
  4378.                     TempODShape newShape = frameShape->Copy(ev);
  4379.                     TempODTransform newXForm = somSelf->ProxyForFrame(ev, embeddedFrame)->transform->Copy(ev);
  4380.                     TempODFrame newFrame = somSelf->MakeEmbeddedFrame(ev, frame,
  4381.                             newShape, newXForm, embeddedPart,
  4382.                             embeddedFrame->IsOverlaid(ev));
  4383.                     embeddedPart->AttachSourceFrame(ev, newFrame, embeddedFrame);
  4384.                 }
  4385.             }
  4386.             delete embeddedFrames; // Delete the copy
  4387.         }
  4388.     else
  4389.         THROW(kODErrInvalidFrame);
  4390.  
  4391.     SOM_CATCH_ALL_ENDTRY
  4392. }
  4393.  
  4394. SOM_Scope void  SOMLINK AppleTest_ContainerDisplayFrameRemoved(AppleTest_Container *somSelf, Environment *ev,
  4395.         ODFrame* frame)
  4396. {
  4397.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  4398.     AppleTest_ContainerMethodDebug("AppleTest_Container","DisplayFrameRemoved");
  4399.  
  4400.     SOM_TRY
  4401.  
  4402. #if ODDebug
  4403.         somPrintf("Draw::DisplayFrameRemoved\n");
  4404. #endif
  4405.  
  4406.     if (frame != (_fPalette ? _fPalette->GetRootFrame(ev) : kODNULL)) {
  4407.         if (_fDisplayFrames->Contains(frame))
  4408.         {
  4409.             OrderedCollection* embeddedFrames = new OrderedCollection;
  4410.             {
  4411.                 OrderedCollectionIterator iter(_fEmbeddedFrames);
  4412.                 for (ODFrame* embeddedFrame = (ODFrame*) iter.First(); 
  4413.                         iter.IsNotComplete(); 
  4414.                         embeddedFrame = (ODFrame*) iter.Next())
  4415.                 {
  4416.                     embeddedFrames->AddLast(embeddedFrame);
  4417.                 }
  4418.             }
  4419.             OrderedCollectionIterator iter(embeddedFrames);
  4420.             for (ODFrame* embeddedFrame = (ODFrame*) iter.First(); 
  4421.                     iter.IsNotComplete(); 
  4422.                     embeddedFrame = (ODFrame*) iter.Next())
  4423.             {
  4424.                 TempODFrame tempFrame = embeddedFrame->AcquireContainingFrame(ev);
  4425.                 if (tempFrame == frame)
  4426.                 {
  4427.                     somSelf->RemoveEmbeddedFrame(ev, embeddedFrame);
  4428.                 }
  4429.             }
  4430.             delete embeddedFrames; // Delete the copy
  4431.     
  4432.             _fSession->GetArbitrator(ev)->RelinquishFocusSet(ev, _fFocusSet,frame);
  4433.     
  4434.             ODFrame* clipboardFocus = _fSession->GetArbitrator(ev)->AcquireFocusOwner(ev, _fClipboardFocus);
  4435.             if ( frame == clipboardFocus )
  4436.             {
  4437.                 _fSession->GetArbitrator(ev)->RelinquishFocus(ev, _fClipboardFocus, frame);
  4438.                 somSelf->FocusLost(ev, _fClipboardFocus, frame);
  4439.             }
  4440.             ODReleaseObject(ev, clipboardFocus);
  4441.  
  4442.             PartInfoRec* pInfo = (PartInfoRec*) frame->GetPartInfo(ev);
  4443.             frame->SetPartInfo(ev, (ODInfoType) kODNULL);
  4444.             delete pInfo;
  4445.             if ( _fDisplayFrames->Remove(frame) )
  4446.                 frame->Release(ev); // DMc - we just called _fDisplayFrames->Remove(frame);
  4447.             
  4448.             OrderedCollectionIterator dIter(_fDisplayFrames);
  4449.             ODFrame*    displayFrame = (ODFrame*) dIter.First();
  4450.             if (dIter.IsNotComplete() == kODFalse) {
  4451.                 somSelf->DestroyPalette(ev);
  4452.             }
  4453.         }
  4454.         else
  4455.             THROW(kODErrInvalidFrame);
  4456.     }
  4457.  
  4458.     SOM_CATCH_ALL_ENDTRY
  4459. }
  4460.  
  4461. SOM_Scope void  SOMLINK AppleTest_ContainerDisplayFrameConnected(AppleTest_Container *somSelf, Environment *ev,
  4462.         ODFrame* frame)
  4463. {
  4464.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  4465.     AppleTest_ContainerMethodDebug("AppleTest_Container","DisplayFrameConnected");
  4466.  
  4467.     SOM_TRY
  4468.  
  4469.     // $$$$$ add frame to fDisplayFrames if reference lazily internalized
  4470. #if defined(ODDebug) && ODDebugConnections
  4471.     somPrintf("Draw %d::DisplayFrameConnected: Connected frame %d\n", somSelf->GetID(ev), frame->GetID(ev));
  4472. #endif
  4473.     if ( !_fDisplayFrames->Contains(frame) )
  4474.     {
  4475.         _fDisplayFrames->AddLast(frame);
  4476.         frame->Acquire(ev);
  4477.         frame->SetDroppable(ev, kODTrue);
  4478.  
  4479.         // $$$$$ If any of our embedded frames had no containing frame, hook them up now
  4480.         // $$$$$ Kludge until I talk to Joshua [cc]  THIS SHOULD BE TAKEN OUT
  4481.         OrderedCollectionIterator bIter(_fEmbeddedFrames);
  4482.         for (ODFrame* embeddedFrame = (ODFrame*)bIter.First(); bIter.IsNotComplete(); embeddedFrame = (ODFrame*)bIter.Next())
  4483.         {
  4484.             TempODFrame tempFrame = embeddedFrame->AcquireContainingFrame(ev);
  4485.             if ( tempFrame == kODNULL )
  4486.             {
  4487.                 embeddedFrame->SetContainingFrame(ev, frame);
  4488. #if defined(ODDebug) && ODDebugConnections
  4489.                 somPrintf("Draw %d::DisplayFrameConnected: Set containing frame of %d to %d\n", 
  4490.                     somSelf->GetID(ev), embeddedFrame->GetID(ev), frame->GetID(ev));
  4491. #endif
  4492.             }
  4493.         }
  4494.     }
  4495. #if defined(ODDebug) && ODDebugConnections
  4496.     else
  4497.         somPrintf("Draw %d::DisplayFrameConnected: No reconnection necessary!\n", somSelf->GetID(ev));
  4498. #endif
  4499.  
  4500.     // hack to allow editor swapping
  4501.     ODStorageUnit* su = kODNULL;
  4502.     if ( !_fTestDrawSU )
  4503.     {
  4504.         ODStorageUnit* su = somSelf->GetStorageUnit(ev);
  4505.         _fTestDrawSU = su->GetDraft(ev)->AcquireStorageUnit(ev, 
  4506.                         ODGetStrongSURefProp(ev, su, kODPropContents, kKindTestDraw));
  4507.     }
  4508.     su = _fTestDrawSU;
  4509.  
  4510.     if (ODSUExistsThenFocus(ev, su, kODPropEmbeddedFrames, 0))
  4511.     {
  4512.          ODStorageUnitRef aSURef;
  4513.         ODULong offset, offsetLimit;
  4514.         Point xform;
  4515.  
  4516.          su->Focus(ev, kODPropEmbeddedFrames,kODPosSame,0,1,kODPosFirstSib); 
  4517.         offsetLimit = su->GetSize(ev);
  4518.         ODShape* newShape = kODNULL;
  4519.         for (offset = 0; offset < offsetLimit;)
  4520.         {
  4521.             su->SetOffset(ev, offset);
  4522.             StorageUnitGetValue(su, ev, sizeof(ODStorageUnitRef), (ODValue)&aSURef);
  4523.             offset += sizeof(ODStorageUnitRef);
  4524.             ODFrame* eFrame =
  4525.                 su->GetDraft(ev)->AcquireFrame(ev, su->GetIDFromStorageUnitRef(ev, aSURef)); // TÇ: eFrame is consumed below.
  4526.  
  4527.             su->SetOffset(ev, offset);
  4528.             StorageUnitGetValue(su, ev, sizeof(ODPlatformTransform), (ODValue)&xform);
  4529.             offset += sizeof(Point);
  4530.             
  4531.             if ( _fEmbeddedFrames->Contains(eFrame) )
  4532.                 ODReleaseObject(ev, eFrame);
  4533.             else
  4534.             {
  4535.                 _fEmbeddedFrames->AddLast((ElementType)(ODFrame*)eFrame);
  4536.     
  4537.                 ODTransform* transform = 
  4538.                     eFrame->CreateTransform(ev)->SetQDOffset(ev, &xform); // DMc SetQDOffset() returns this. TÇ: transform is consumed below.
  4539.                 
  4540.                 TempODShape frameShape = eFrame->AcquireFrameShape(ev, kODNULL);
  4541.                 if( newShape )
  4542.                     newShape->CopyFrom(ev, frameShape);
  4543.                 else
  4544.                     newShape = frameShape->Copy(ev);
  4545.                     
  4546.                 // TÇ: $$$$$ Should really be using CreateFrameProxy.
  4547.                 newShape->Transform(ev, transform);
  4548.                 RgnHandle newRegion = newShape->CopyQDRegion(ev);
  4549.                 _fContents->AddLast((ElementType)(new Proxy(newRegion, (ODFrame*)eFrame, transform))); //  TÇ: transform is consumed here.
  4550.             }
  4551.         }
  4552.         if (newShape) newShape->Release(ev); newShape = kODNULL;
  4553.  
  4554.     }
  4555.  
  4556.     PartInfoRec* pInfo = (PartInfoRec*) frame->GetPartInfo(ev);
  4557.     if (frame->IsRoot(ev))
  4558.         pInfo->fNeedsActivating = kODTrue;
  4559.  
  4560.     SOM_CATCH_ALL_ENDTRY
  4561. }
  4562.  
  4563. SOM_Scope void  SOMLINK AppleTest_ContainerDisplayFrameClosed(AppleTest_Container *somSelf, Environment *ev,
  4564.         ODFrame* frame)
  4565. {
  4566.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  4567.     AppleTest_ContainerMethodDebug("AppleTest_Container","DisplayFrameClosed");
  4568.  
  4569.     SOM_TRY
  4570.  
  4571.     if (_fDisplayFrames->Contains(frame))
  4572.     {
  4573.  
  4574. #if defined(ODDebug) && ODDebugConnections
  4575.         somPrintf("Draw %d::DisplayFrameClosed: Removing frame %d\n", somSelf->GetID(ev), frame->GetID(ev));
  4576. #endif
  4577.  
  4578.         OrderedCollection* embeddedFrames = new OrderedCollection;
  4579.         {
  4580.             OrderedCollectionIterator iter(_fEmbeddedFrames);
  4581.             for (ODFrame* embeddedFrame = (ODFrame*) iter.First(); 
  4582.                     iter.IsNotComplete(); 
  4583.                     embeddedFrame = (ODFrame*) iter.Next())
  4584.             {
  4585.                 embeddedFrames->AddLast(embeddedFrame);
  4586.             }
  4587.         }
  4588.         
  4589.         OrderedCollectionIterator iter(embeddedFrames);
  4590.         for (ODFrame* embeddedFrame = (ODFrame*) iter.First(); 
  4591.                 iter.IsNotComplete(); 
  4592.                 embeddedFrame = (ODFrame*) iter.Next())
  4593.         {
  4594.             TempODFrame tempFrame = embeddedFrame->AcquireContainingFrame(ev);
  4595.             if (tempFrame == frame)
  4596.             {
  4597.                 embeddedFrame->Close(ev);
  4598.                 _fEmbeddedFrames->Remove(embeddedFrame);
  4599.             }
  4600.         }
  4601.         delete embeddedFrames; // Delete the copy
  4602.         
  4603.         _fSession->GetArbitrator(ev)->RelinquishFocusSet(ev, _fFocusSet, frame);
  4604.  
  4605.         ODFrame* clipboardFocus = _fSession->GetArbitrator(ev)->AcquireFocusOwner(ev, _fClipboardFocus);
  4606.         if ( frame == clipboardFocus )
  4607.         {
  4608.             _fSession->GetArbitrator(ev)->RelinquishFocus(ev, _fClipboardFocus, frame);
  4609.             somSelf->FocusLost(ev, _fClipboardFocus, frame);
  4610.         }
  4611.         ODReleaseObject(ev, clipboardFocus);
  4612.         
  4613.         PartInfoRec* pInfo = (PartInfoRec*) frame->GetPartInfo(ev);
  4614.         frame->SetPartInfo(ev, (ODInfoType) kODNULL);
  4615.         delete pInfo;
  4616.         _fDisplayFrames->Remove(frame);
  4617.         ODReleaseObject(ev,frame); // DMc - we just called _fDisplayFrames->Remove(frame);
  4618.     }
  4619.     else
  4620.         THROW(kODErrInvalidFrame);
  4621.  
  4622.     SOM_CATCH_ALL_ENDTRY
  4623. }
  4624.  
  4625. SOM_Scope void  SOMLINK AppleTest_ContainerFrameShapeChanged(AppleTest_Container *somSelf, Environment *ev,
  4626.         ODFrame* frame)
  4627. {
  4628.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  4629.     AppleTest_ContainerMethodDebug("AppleTest_Container","FrameShapeChanged");
  4630.  
  4631.     SOM_TRY
  4632.  
  4633.     if (_fDisplayFrames->Contains(frame))
  4634.     {
  4635.         /// !!! should leave UsedShape and ActiveShape null to inherit FrameShape
  4636. //        ODShape* scratch;
  4637. //        scratch = new ODShape();
  4638. //        scratch->CopyFrom(frame->AcquireFrameShape(ev, kODNULL));
  4639. //        frame->ChangeUsedShape(ev, scratch);
  4640. //         scratch = new ODShape();
  4641. //        scratch->CopyFrom(frame->AcquireFrameShape(ev, kODNULL));
  4642. //        frame->ChangeActiveShape(ev, scratch);
  4643.     }
  4644.     else
  4645.         THROW(kODErrInvalidFrame);
  4646.  
  4647.     SOM_CATCH_ALL_ENDTRY
  4648. }
  4649.  
  4650. SOM_Scope void  SOMLINK AppleTest_ContainerViewTypeChanged(AppleTest_Container *somSelf, Environment *ev,
  4651.         ODFrame* frame)
  4652. {
  4653.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  4654.     AppleTest_ContainerMethodDebug("AppleTest_Container","ViewTypeChanged");
  4655.  
  4656.     SOM_TRY
  4657.  
  4658.     if (_fDisplayFrames->Contains(frame))
  4659.         { /* $$$$$ change viewType of frame */ }
  4660.     else
  4661.         THROW(kODErrInvalidFrame);
  4662.  
  4663.     SOM_CATCH_ALL_ENDTRY
  4664. }
  4665.  
  4666. SOM_Scope void  SOMLINK AppleTest_ContainerPresentationChanged(AppleTest_Container *somSelf, Environment *ev,
  4667.         ODFrame* frame)
  4668. {
  4669.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  4670.     AppleTest_ContainerMethodDebug("AppleTest_Container","PresentationChanged");
  4671.  
  4672.     SOM_TRY
  4673.  
  4674.     if (_fDisplayFrames->Contains(frame))
  4675.         { /* $$$$$ change presentation of frame */ }
  4676.     else
  4677.         THROW(kODErrInvalidFrame);
  4678.  
  4679.     SOM_CATCH_ALL_ENDTRY
  4680. }
  4681.  
  4682. SOM_Scope void  SOMLINK AppleTest_ContainerSequenceChanged(AppleTest_Container *somSelf, Environment *ev,
  4683.         ODFrame* frame)
  4684. {
  4685.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  4686.     AppleTest_ContainerMethodDebug("AppleTest_Container","SequenceChanged");
  4687.  
  4688.     SOM_TRY
  4689.  
  4690.     SOM_CATCH_ALL_ENDTRY
  4691. }
  4692.  
  4693. SOM_Scope ODInfoType  SOMLINK AppleTest_ContainerReadPartInfo(AppleTest_Container *somSelf, Environment *ev,
  4694.         ODFrame* frame,
  4695.         ODStorageUnitView* storageUnitView)
  4696. {
  4697.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  4698.     AppleTest_ContainerMethodDebug("AppleTest_Container","ReadPartInfo");
  4699.  
  4700.     SOM_TRY
  4701.  
  4702.     ODUnused(frame);
  4703.     ODStorageUnit* su = storageUnitView->GetStorageUnit(ev);
  4704.     TempODPropertyName propName = storageUnitView->GetProperty(ev);
  4705.     
  4706.     PartInfoRec* partInfo = new PartInfoRec;
  4707.     RGBColor forDebuggingRGBColor = rgbRed;
  4708.     if ( ODSUExistsThenFocus(ev, su, propName, kKindTestDraw) )
  4709.     {        
  4710.         StorageUnitGetValue(su, ev, sizeof(RGBColor),
  4711.                                     (ODValue)&forDebuggingRGBColor);
  4712. //        StorageUnitViewGetValue(storageUnitView, ev, sizeof(RGBColor),
  4713. //                                    (ODValue)&(partInfo->bgColor));
  4714.         /*
  4715.         ODBoolean needsActivating;
  4716.         StorageUnitViewGetValue(storageUnitView, ev, sizeof(ODBoolean),
  4717.                                     (ODValue)&(needsActivating));
  4718.         partInfo->fNeedsActivating = needsActivating;
  4719.                                     
  4720.         OrderedCollectionIterator d(_fDisplayFrames);
  4721.         ODFrame* dispFrame = (ODFrame*) d.First();
  4722.         */
  4723.     }
  4724.     else
  4725.     {
  4726.         WARN("Persistent partInfo is missing from this frame. Making one up.");
  4727.     }
  4728.     
  4729.     partInfo->bgColor = forDebuggingRGBColor;
  4730.     return (ODInfoType)partInfo;
  4731.  
  4732.     SOM_CATCH_ALL_ENDTRY
  4733.     return kODNULL;
  4734. }
  4735.  
  4736. SOM_Scope void  SOMLINK AppleTest_ContainerWritePartInfo(AppleTest_Container *somSelf, Environment *ev,
  4737.         ODInfoType partInfo,
  4738.         ODStorageUnitView* storageUnitView)
  4739. {
  4740.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  4741.     AppleTest_ContainerMethodDebug("AppleTest_Container","WritePartInfo");
  4742.  
  4743.     SOM_TRY
  4744.  
  4745.     if ( partInfo )
  4746.     {
  4747.         ODStorageUnit* su = storageUnitView->GetStorageUnit(ev);
  4748.         TempODPropertyName propName = storageUnitView->GetProperty(ev);
  4749.  
  4750.         ODSUForceFocus(ev, su, propName, kKindTestDraw);
  4751.  
  4752.         RGBColor forDebuggingRGBColor ;
  4753.         forDebuggingRGBColor = ((PartInfoRec*)partInfo)->bgColor;
  4754.         StorageUnitSetValue(su, ev, sizeof(RGBColor), (ODValue)&forDebuggingRGBColor);
  4755.         /*
  4756.         ODBoolean needsActivating = ((PartInfoRec*)partInfo)->fNeedsActivating 
  4757.                                     || ((PartInfoRec*)partInfo)->fIsActive;
  4758.         StorageUnitViewSetValue(storageUnitView, ev, sizeof(ODBoolean),
  4759.                                     (ODValue)&needsActivating);
  4760.         */
  4761.     }
  4762.  
  4763.     SOM_CATCH_ALL_ENDTRY
  4764. }
  4765.  
  4766. SOM_Scope void  SOMLINK AppleTest_ContainerClonePartInfo(AppleTest_Container *somSelf, Environment *ev,
  4767.         ODDraftKey key,
  4768.         ODInfoType partInfo,
  4769.         ODStorageUnitView* storageUnitView,
  4770.         ODFrame* scopeFrame)
  4771. {
  4772.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  4773.     AppleTest_ContainerMethodDebug("AppleTest_Container","WritePartInfo");
  4774.  
  4775.     SOM_TRY
  4776.  
  4777.     if (partInfo)
  4778.     {
  4779.         ODStorageUnit* su = storageUnitView->GetStorageUnit(ev);
  4780.         TempODPropertyName propName = storageUnitView->GetProperty(ev);
  4781.  
  4782.         ODSUForceFocus(ev, su, propName, kKindTestDraw);
  4783.  
  4784.         RGBColor forDebuggingRGBColor ;
  4785.         forDebuggingRGBColor = ((PartInfoRec*)partInfo)->bgColor;
  4786.         StorageUnitSetValue(su, ev, sizeof(RGBColor), (ODValue)&forDebuggingRGBColor);
  4787.         /*
  4788.         ODBoolean needsActivating = ((PartInfoRec*)partInfo)->fNeedsActivating 
  4789.                                     || ((PartInfoRec*)partInfo)->fIsActive;
  4790.         StorageUnitViewSetValue(storageUnitView, ev, sizeof(ODBoolean),
  4791.                                     (ODValue)&needsActivating);
  4792.         */
  4793.     }
  4794.  
  4795.     SOM_CATCH_ALL_ENDTRY
  4796. }
  4797.  
  4798. SOM_Scope ODID  SOMLINK AppleTest_ContainerOpen(AppleTest_Container *somSelf, Environment *ev,
  4799.         ODFrame* frame)
  4800. {
  4801.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  4802.     AppleTest_ContainerMethodDebug("AppleTest_Container","Open");
  4803.  
  4804.     SOM_TRY
  4805.  
  4806.     TempODWindow window = kODNULL;
  4807.     ODID windowID = 0;
  4808.  
  4809.     if (frame) // Doing a View As Window or Open Root
  4810.     {
  4811.         if (frame->IsRoot(ev))    // Create Window For Root Frame
  4812.         {
  4813.             WindowProperties props;
  4814.             if (BeginGetWindowProperties(ev, frame, &props))
  4815.             {
  4816.                 ODPlatformWindow platformWindow = NewCWindow(kODNULL, &(props.boundsRect), props.title, 
  4817.                             kODFalse, props.procID, (WindowPtr)-1L, props.hasCloseBox, props.refCon);
  4818.                 
  4819.                         
  4820.                 window =  _fSession->GetWindowState(ev)->RegisterWindowForFrame(ev, platformWindow, 
  4821.                                                                 frame,
  4822.                                                                  props.isRootWindow,    // Keeps draft open
  4823.                                                                  kODTrue,    // Is resizable
  4824.                                                                  kODFalse,    // Is floating
  4825.                                                                 kODTrue,    // should save
  4826.                                                                 kODTrue,    // should dispose
  4827.                                                                 props.sourceFrame);
  4828.                 EndGetWindowProperties(ev, &props); // Release source frame
  4829.                 window->Open(ev);    
  4830.             }
  4831.             else
  4832.             {
  4833.                 Rect windRect;
  4834.                 SetRect(&windRect, 100, 100, 300, 300);    
  4835.                 ODPlatformWindow platformWindow = NewCWindow(kODNULL, &windRect, "\p", kODFalse, zoomDocProc, (WindowPtr)-1L, true, kODNULL);
  4836.                         
  4837.                 window =  _fSession->GetWindowState(ev)->RegisterWindowForFrame(ev, platformWindow, 
  4838.                                                                 frame,
  4839.                                                                  kODTrue,    // Keeps draft open
  4840.                                                                  kODTrue,    // Is resizable
  4841.                                                                  kODFalse,    // Is floating
  4842.                                                                 kODTrue,    // should save
  4843.                                                                 kODTrue,    // should dispose
  4844.                                                                 kODNULL);
  4845.                 window->Open(ev);    
  4846.                 window->AdjustWindowShape(ev);
  4847.             }
  4848.             window->Show(ev);
  4849.         }
  4850.         else    // View In Window
  4851.         {
  4852.             window = _fSession->GetWindowState(ev)->AcquireWindow(ev, _fWindowID);
  4853.             if (window)
  4854.             {
  4855.                 window->Select(ev);
  4856.             }
  4857.             else
  4858.             {
  4859.                 window = somSelf->CreateWindow(ev, frame);
  4860.                 _fWindowID = window->GetID(ev);
  4861.                 window->Open(ev);
  4862.                 window->Show(ev);
  4863.                 window->Select(ev);            
  4864.             }
  4865.         }
  4866.     }
  4867.     else
  4868.     {
  4869.         window = somSelf->CreateWindow(ev, frame);
  4870.         _fWindowID = window->GetID(ev);
  4871.         window->Open(ev);
  4872.         window->Show(ev);
  4873.         window->Select(ev);            
  4874.     }
  4875.     windowID = window->GetID(ev);
  4876.     return windowID;
  4877.     
  4878.  
  4879.     SOM_CATCH_ALL_ENDTRY
  4880.     return kODNULLID;
  4881. }
  4882.  
  4883. SOM_Scope ODFrame*  SOMLINK AppleTest_ContainerRequestEmbeddedFrame(AppleTest_Container *somSelf, Environment *ev,
  4884.         ODFrame* containingFrame,
  4885.         ODFrame* baseFrame,
  4886.         ODShape* frameShape,
  4887.         ODPart* embedPart,
  4888.         ODTypeToken viewType,
  4889.         ODTypeToken presentation,
  4890.         ODBoolean isOverlaid)
  4891. {
  4892.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  4893.     AppleTest_ContainerMethodDebug("AppleTest_Container","RequestEmbeddedFrame");
  4894.  
  4895.     SOM_TRY
  4896.  
  4897.     ODFrame* embeddedFrame;
  4898.     ODTransform* externalXForm = containingFrame->CreateTransform(ev);
  4899.     
  4900.     ODSLong count = 1 + _fContents->Count();
  4901.  
  4902.     Point ptTemp;
  4903.     SetPt(&ptTemp,(short)(count*20),(short)(count*20));
  4904.     externalXForm->SetQDOffset(ev, &ptTemp);
  4905.     embeddedFrame = somSelf->MakeEmbeddedFrame(ev,
  4906.                                                containingFrame,
  4907.                                                frameShape,
  4908.                                                externalXForm,
  4909.                                                embedPart,
  4910.                                                isOverlaid);
  4911.     
  4912.     embeddedFrame->SetViewType(ev, viewType);
  4913.     embeddedFrame->SetPresentation(ev, presentation);
  4914.     
  4915.     ODFrameFacetIterator* facets = containingFrame->CreateFacetIterator(ev);
  4916.     for (ODFacet* facet = facets->First(ev); facets->IsNotComplete(ev);
  4917.             facet = facets->Next(ev))
  4918.     {
  4919.         TempODShape frameShape = embeddedFrame->AcquireFrameShape(ev, kODNULL);
  4920.         TempODShape clip = frameShape->Copy(ev);
  4921.         TempODTransform xform = somSelf->ProxyForFrame(ev, embeddedFrame)->transform->Copy(ev);
  4922.         facet->CreateEmbeddedFacet(ev, embeddedFrame, clip, xform,
  4923.                                     kODNULL, kODNULL, kODNULL, kODFrameInFront);
  4924.     }
  4925.     delete facets;
  4926.     somSelf->ClipEmbeddedFrames(ev, containingFrame);
  4927.     containingFrame->Invalidate(ev, kODNULL, kODNULL);
  4928.     
  4929.     
  4930.     return embeddedFrame;
  4931.  
  4932.     SOM_CATCH_ALL_ENDTRY
  4933.     return kODNULL;
  4934. }
  4935.  
  4936. SOM_Scope void  SOMLINK AppleTest_ContainerRemoveEmbeddedFrame(AppleTest_Container *somSelf, Environment *ev,
  4937.         ODFrame* embeddedFrame)
  4938. {
  4939.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  4940.     AppleTest_ContainerMethodDebug("AppleTest_Container","RemoveEmbeddedFrame");
  4941.  
  4942.     SOM_TRY
  4943.     
  4944.     TempODFrame containingFrame = embeddedFrame->AcquireContainingFrame(ev);
  4945.  
  4946.     embeddedFrame->Acquire(ev);
  4947.  
  4948.     somSelf->DeleteFrameProxy(ev, somSelf->ProxyForFrame(ev, embeddedFrame));
  4949.     
  4950.     embeddedFrame->Remove(ev);
  4951.         
  4952.     somSelf->ClipEmbeddedFrames(ev, containingFrame);
  4953.  
  4954.     SOM_CATCH_ALL_ENDTRY
  4955. }
  4956.  
  4957. SOM_Scope ODShape*  SOMLINK AppleTest_ContainerRequestFrameShape(AppleTest_Container *somSelf, Environment *ev,
  4958.         ODFrame* embeddedFrame,
  4959.         ODShape* frameShape)
  4960. {
  4961.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  4962.     AppleTest_ContainerMethodDebug("AppleTest_Container","RequestFrameShape");
  4963.  
  4964.     SOM_TRY
  4965.  
  4966.     if (_fEmbeddedFrames->Contains(embeddedFrame))
  4967.     {    // find frame proxy and fix cached region
  4968.         Proxy* p = somSelf->ProxyForFrame(ev, embeddedFrame);
  4969.         if (p)
  4970.         {
  4971.             ODShape* scratch = frameShape->Copy(ev);
  4972.             scratch->Transform(ev, p->transform);
  4973.             p->region = scratch->CopyQDRegion(ev);
  4974.             scratch->Release(ev); scratch = kODNULL;
  4975.  
  4976.             p->frame->Invalidate(ev, kODNULL, kODNULL);
  4977.         //    p->frame->Invalidate(ev, frameShape, kODNULL);    // $$$$$ why do we need this?
  4978.  
  4979.             if (_fSelection->Contains(p)) { /* !!! fix highlighting */ };
  4980.             
  4981.             // fix clipping of obscured frames
  4982.             TempODFrame tempFrame = embeddedFrame->AcquireContainingFrame(ev);
  4983.             somSelf->ClipEmbeddedFrames(ev, tempFrame);
  4984.         }
  4985.     }
  4986.     else
  4987.         THROW(kODErrInvalidFrame);
  4988.  
  4989.     frameShape->Acquire(ev);
  4990.     return frameShape;
  4991.  
  4992.     SOM_CATCH_ALL_ENDTRY
  4993.     return kODNULL;
  4994. }
  4995.  
  4996. SOM_Scope void  SOMLINK AppleTest_ContainerUsedShapeChanged(AppleTest_Container *somSelf, Environment *ev,
  4997.         ODFrame* embeddedFrame)
  4998. {
  4999.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  5000.     AppleTest_ContainerMethodDebug("AppleTest_Container","UsedShapeChanged");
  5001.  
  5002.     SOM_TRY
  5003.  
  5004.     if (_fEmbeddedFrames->Contains(embeddedFrame))
  5005.     {
  5006.         TempODFrame tempFrame = embeddedFrame->AcquireContainingFrame(ev);
  5007.         somSelf->ClipEmbeddedFrames(ev, tempFrame);
  5008.     }
  5009.     else
  5010.         THROW(kODErrInvalidFrame);
  5011.  
  5012.     SOM_CATCH_ALL_ENDTRY
  5013. }
  5014.  
  5015. SOM_Scope ODShape*  SOMLINK AppleTest_ContainerAdjustBorderShape(AppleTest_Container *somSelf, Environment *ev,
  5016.         ODFacet* embeddedFacet,
  5017.         ODShape* shape)
  5018. {
  5019.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  5020.     AppleTest_ContainerMethodDebug("AppleTest_Container","AdjustBorderShape");
  5021.  
  5022.     SOM_TRY
  5023.  
  5024.     if ( embeddedFacet == kODNULL )
  5025.         THROW(kODErrIllegalNullInput);        // $$$$$ kODErrIllegalNullFacetInput
  5026.     
  5027.     ODFacet* dispFacet = embeddedFacet->GetContainingFacet(ev);
  5028.     
  5029.     TempODPart tempPart = dispFacet->GetFrame(ev)->AcquirePart(ev); // for ASSERT below
  5030.     ASSERT(tempPart == _fPartWrapper, kODErrInvalidFacet);
  5031.     
  5032.     if ( shape == kODNULL )
  5033.         return kODNULL;
  5034.     
  5035.     TempODShape adjusted = shape->Copy(ev);
  5036.     ODShape* returnValue = kODNULL;
  5037.     
  5038.     { TempODTransform xform = embeddedFacet->AcquireExternalTransform(ev, kNoBias);
  5039.       adjusted->Transform(ev, xform);
  5040.     }
  5041.     
  5042.     { TempODShape dispShape = dispFacet->GetFrame(ev)->AcquireUsedShape(ev, kNoBias);
  5043.       adjusted->Intersect(ev, dispShape);
  5044.     }
  5045.     
  5046.     ODFacet* facet = kODNULL;
  5047.     ODBoolean above = kODFalse;
  5048.     ODFacetIterator* facets = dispFacet->CreateFacetIterator(ev, kODChildrenOnly, kODBackToFront);
  5049.     for (facet = facets->First(ev);
  5050.             facets->IsNotComplete(ev);
  5051.             facet = facets->Next(ev))
  5052.     {
  5053.         if ( above )
  5054.         {
  5055.             TempODShape tShape = ODCopyAndRelease(ev, facet->GetFrame(ev)->AcquireUsedShape(ev, kNoBias));
  5056.             TempODTransform xform = facet->AcquireExternalTransform(ev, kNoBias);
  5057.             tShape->Transform(ev, xform);
  5058.             adjusted->Subtract(ev, tShape);
  5059.         }
  5060.         else
  5061.         {
  5062.             above = ( facet == embeddedFacet );
  5063.         }
  5064.     }
  5065.     delete facets;
  5066.  
  5067.     { TempODTransform xform = embeddedFacet->AcquireExternalTransform(ev, kNoBias);
  5068.       adjusted->InverseTransform(ev, xform);
  5069.     }
  5070.     
  5071.     returnValue = adjusted; adjusted = kODNULL;
  5072.     
  5073.     return returnValue;
  5074.  
  5075.     SOM_CATCH_ALL_ENDTRY
  5076.     return kODNULL;
  5077. }
  5078.  
  5079. SOM_Scope void  SOMLINK AppleTest_ContainerFacetAdded(AppleTest_Container *somSelf, Environment *ev,
  5080.         ODFacet* facet)
  5081. {
  5082.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  5083.     AppleTest_ContainerMethodDebug("AppleTest_Container","FacetAdded");
  5084.  
  5085.     SOM_TRY
  5086.  
  5087. #if defined(ODDebug) && ODDebugConnections
  5088.         somPrintf("Draw %d::FacetAdded:  Added facet %x; display frames =", somSelf->GetID(ev), facet);
  5089.         OrderedCollectionIterator aIter(_fDisplayFrames);
  5090.         for (ODFrame* aFrame = (ODFrame*)aIter.First(); aIter.IsNotComplete(); aFrame = (ODFrame*)aIter.Next())
  5091.             somPrintf (" %d", aFrame->GetID(ev));
  5092.         somPrintf ("\n");
  5093. #endif
  5094.  
  5095.     ODFrame* dispFrame = facet->GetFrame(ev);
  5096.     if (!_fDisplayFrames->Contains(dispFrame))
  5097.         THROW(kODErrInvalidFacet);
  5098.  
  5099.     OrderedCollectionIterator frames(_fEmbeddedFrames);
  5100.     for (ODFrame* frame = (ODFrame*) frames.First(); 
  5101.             frames.IsNotComplete(); 
  5102.             frame = (ODFrame*) frames.Next())
  5103.     {
  5104.         TempODFrame tempFrame = frame->AcquireContainingFrame(ev);
  5105.         if (tempFrame == dispFrame)
  5106.         {
  5107.             TempODShape frameShape = frame->AcquireFrameShape(ev, kODNULL);
  5108.             TempODShape clip = frameShape->Copy(ev);
  5109.             Proxy* p = somSelf->ProxyForFrame(ev, frame);
  5110.             TempODTransform xform = p->transform->Copy(ev);
  5111.             facet->CreateEmbeddedFacet(ev, frame,
  5112.                                         clip, xform, kODNULL, kODNULL,
  5113.                                         kODNULL, kODFrameBehind);
  5114.         }
  5115.     }
  5116.     
  5117.     somSelf->ClipEmbeddedFacets(ev, facet);
  5118.  
  5119.     SOM_CATCH_ALL_ENDTRY
  5120. }
  5121.  
  5122. SOM_Scope void  SOMLINK AppleTest_ContainerFacetRemoved(AppleTest_Container *somSelf, Environment *ev,
  5123.         ODFacet* facet)
  5124. {
  5125.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  5126.     AppleTest_ContainerMethodDebug("AppleTest_Container","FacetRemoved");
  5127.  
  5128.     SOM_TRY
  5129.  
  5130. #if defined(ODDebug) && ODDebugConnections
  5131.         somPrintf("Draw %d::FacetRemoved: Facet %x removed; display frames =", somSelf->GetID(ev) , facet);
  5132.         OrderedCollectionIterator aIter(_fDisplayFrames);
  5133.         for (ODFrame* aFrame = (ODFrame*)aIter.First(); aIter.IsNotComplete(); aFrame = (ODFrame*)aIter.Next())
  5134.             somPrintf (" %d", aFrame->GetID(ev));
  5135.         somPrintf ("\n");
  5136. #endif
  5137.  
  5138.     ODFrame* dispFrame = facet->GetFrame(ev);
  5139.     if (!_fDisplayFrames->Contains(dispFrame))
  5140.     {
  5141. #if defined(ODDebug) && ODDebugConnections
  5142.         somPrintf("Draw::FacetRemoved: Frame ID = %d is not a display frame\n", dispFrame->GetID(ev));
  5143. #endif
  5144.         THROW(kODErrInvalidFacet);
  5145.     }
  5146.     
  5147.     OrderedCollection* children = new OrderedCollection;
  5148.     ODFacetIterator* facets = facet->CreateFacetIterator(ev, kODChildrenOnly, kODFrontToBack);
  5149.     ODFacet* childFacet;
  5150.     for (childFacet = facets->First(ev);
  5151.         facets->IsNotComplete(ev);
  5152.         childFacet = facets->Next(ev))
  5153.     {
  5154.         children->AddLast(childFacet);
  5155.     }
  5156.     delete facets;
  5157.     OrderedCollectionIterator iter(children);
  5158.     for (childFacet = (ODFacet*)iter.First();
  5159.             iter.IsNotComplete();
  5160.             childFacet = (ODFacet*)iter.Next())
  5161.     {
  5162.         facet->RemoveFacet(ev, childFacet);
  5163.         delete childFacet;
  5164.     }
  5165.     delete children;
  5166.  
  5167.     SOM_CATCH_ALL_ENDTRY
  5168. }
  5169.  
  5170. SOM_Scope void  SOMLINK AppleTest_ContainerCanvasChanged(AppleTest_Container *somSelf, Environment *ev,
  5171.         ODFacet* facet)
  5172. {
  5173.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  5174.     AppleTest_ContainerMethodDebug("AppleTest_Container","CanvasChanged");
  5175.  
  5176.     SOM_TRY
  5177.  
  5178.     ODUnused(facet);
  5179.  
  5180.     SOM_CATCH_ALL_ENDTRY
  5181. }
  5182.  
  5183. SOM_Scope void  SOMLINK AppleTest_ContainerGeometryChanged(AppleTest_Container *somSelf,
  5184.         Environment *ev, ODFacet* facet,
  5185.         ODBoolean clipShapeChanged,
  5186.         ODBoolean externalTransformChanged)
  5187. {
  5188.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  5189.     AppleTest_ContainerMethodDebug("AppleTest_Container","GeometryChanged");
  5190.     
  5191.     SOM_TRY
  5192.  
  5193.     facet->Invalidate(ev, kODNULL, kODNULL);
  5194.     
  5195.     somSelf->ClipEmbeddedFacets(ev, facet);  // extra work, but gives correct display
  5196.  
  5197.     SOM_CATCH_ALL_ENDTRY
  5198. }
  5199.  
  5200. SOM_Scope void  SOMLINK AppleTest_ContainerDraw(AppleTest_Container *somSelf, Environment *ev,
  5201.         ODFacet* facet,
  5202.         ODShape* invalidShape)
  5203. {
  5204.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  5205.     AppleTest_ContainerMethodDebug("AppleTest_Container","Draw");
  5206.  
  5207.     SOM_TRY
  5208.  
  5209.     ODBoolean drawing = facet->GetCanvas(ev)->IsDynamic(ev);
  5210.     
  5211.     ODUnused(invalidShape);
  5212.  
  5213.     ODFrame* displayFrame = facet->GetFrame(ev);
  5214.     if (_fDisplayFrames->Contains(displayFrame))    
  5215.     {
  5216.         // transform grafport
  5217.         
  5218.         CFocus prepareForRendering(ev, facet);
  5219.  
  5220.         RgnHandle    bRgn;
  5221.         
  5222.         { TempODShape frameShape = displayFrame->AcquireFrameShape(ev, kODNULL); // DMc refcount - make temp
  5223.           bRgn = frameShape->GetQDRegion(ev);
  5224.         }
  5225.         
  5226.         if ((drawing) && (displayFrame->GetPresentation(ev) == _fSession->Tokenize(ev, kDrawPresPalette)))
  5227.         {
  5228.             Rect        bRect;
  5229.             Rect        colorRect;                
  5230.             ODUShort    i;
  5231.             RGBColor    bgColor;
  5232.             ODSShort    height;
  5233.             OSErr        err = noErr;
  5234.     
  5235.             RGBBackColor(&rgbBlack);
  5236.             EraseRgn(bRgn);
  5237.             
  5238.             bRect.left = (**bRgn).rgnBBox.left;
  5239.             bRect.top = (**bRgn).rgnBBox.top;
  5240.             bRect.bottom = (**bRgn).rgnBBox.bottom;
  5241.             bRect.right = (**bRgn).rgnBBox.right;
  5242.             
  5243.             height = ((bRect.bottom - bRect.top) - kMargin - ((kNumColors-1) * kMargin) - kMargin) / kNumColors;
  5244.                 
  5245.             colorRect.left = bRect.left + kMargin;
  5246.             colorRect.right = bRect.right - kMargin;
  5247.             colorRect.top = bRect.top + kMargin;
  5248.             colorRect.bottom = colorRect.top + height;
  5249.             
  5250.             for (i = 0; i < kNumColors; i++) {
  5251.                 somSelf->GetBGColor(ev, i, &bgColor);
  5252.                 RGBBackColor(&bgColor);
  5253.                 EraseRect(&colorRect);
  5254.                 colorRect.top = colorRect.bottom + kMargin;
  5255.                 colorRect.bottom = colorRect.top + height;
  5256.             }
  5257.             RGBBackColor(&rgbWhite);
  5258.         }
  5259.         else            // <eeh> removed the following test until Joshua fixes frame presentation externalization
  5260. //        if ( facet->GetFrame(ev)->GetPresentation(ev) == _fSession->Tokenize(ev, kDrawPresNormal) )
  5261.         {
  5262.             ODTypeToken curView = displayFrame->GetViewType(ev);
  5263. // $$$$$ until Joshua fixes...see above
  5264.             if (curView == _fSession->Tokenize(ev, kODViewAsLargeIcon))
  5265.             {
  5266.                 Rect rect32;
  5267.                 SetRect(&rect32, 0, 0, kODLargeIconSize, kODLargeIconSize);
  5268.                 PlotIconSuite(&rect32,atAbsoluteCenter,ttNone,_fLargeIcons);
  5269.             }
  5270.             else if (curView == _fSession->Tokenize(ev, kODViewAsSmallIcon))
  5271.             {
  5272.                 Rect rect16;
  5273.                 SetRect(&rect16, 0, 0, kODSmallIconSize, kODSmallIconSize);
  5274.                 PlotIconSuite(&rect16,atAbsoluteCenter,ttNone,_fSmallIcons);
  5275.             }
  5276.             else    // if (curView == _fSession->Tokenize(ev, kODViewAsFrame))
  5277.             {
  5278.                 PartInfoRec* pInfo = (PartInfoRec*) displayFrame->GetPartInfo(ev);
  5279.                 
  5280.                 // paint the background
  5281.             
  5282.                 PenNormal();
  5283.         
  5284.                 RGBColor saveRGB;
  5285.                 GetBackColor(&saveRGB);
  5286.                 RGBColor bgRGB = pInfo->bgColor;
  5287.  
  5288.                 RGBBackColor(&bgRGB);
  5289.                 EraseRect(&(**bRgn).rgnBBox);
  5290.                 RGBBackColor(&saveRGB);        // restore old bg color
  5291.  
  5292. #if ODDebug
  5293.                 // !!! test code for debugging help
  5294.                 // display frame and facet object addresses
  5295.                 char splat[96];
  5296.                 
  5297.                 PenNormal();
  5298.                 TextFace( normal );
  5299.                 TextFont( courier );
  5300.                 TextMode( srcOr );
  5301.                 TextSize( 9 );
  5302.                 short vertical = 0;
  5303.                 
  5304.                 // Inflated by 1 because dispatcher has acquired window
  5305.                 sprintf(splat, "Window:  <%p> [%d]", facet->GetWindow(ev), (facet->GetWindow(ev)->GetRefCount(ev) - 1));
  5306.                 MoveTo( 4, vertical+=12 );
  5307.                 DrawText( &splat, 0, strlen(splat) );
  5308.  
  5309.                 // this part's refcount is inflated by 1 from Facet::Draw calling AcquirePart
  5310.                 sprintf(splat, "part:  <%p> [%d]", somSelf, (somSelf->GetRefCount(ev) - 1));
  5311.                 MoveTo( 4, vertical+=12 );
  5312.                 DrawText( &splat, 0, strlen(splat) );
  5313.                 
  5314.                 sprintf(splat, "wrap:  <%p>", _fPartWrapper);
  5315.                 MoveTo( 4, vertical+=12 );
  5316.                 DrawText( &splat, 0, strlen(splat) );
  5317.                 
  5318.                 ODFrame* printFrame = facet->GetFrame(ev);
  5319.                 sprintf(splat, "frame: <%p> [%d]", printFrame, printFrame->GetRefCount(ev));
  5320.                 MoveTo( 4, vertical+=12 );
  5321.                 DrawText( &splat, 0, strlen(splat) );
  5322.                 
  5323.                 {
  5324.                 TempODShape tempShape = printFrame->AcquireFrameShape(ev, kODNULL);
  5325.                 sprintf(splat, "  framShape: [%d]", (tempShape->GetRefCount(ev) - 1));
  5326.                 MoveTo( 4, vertical+=12 );
  5327.                 DrawText( &splat, 0, strlen(splat) );
  5328.                 }
  5329.                 
  5330.                 {
  5331.                 TempODShape tempShape = printFrame->AcquireUsedShape(ev, kODNULL);
  5332.                 sprintf(splat, "  usedShape: [%d]", (tempShape->GetRefCount(ev) - 1));
  5333.                 MoveTo( 4, vertical+=12 );
  5334.                 DrawText( &splat, 0, strlen(splat) );
  5335.                 }
  5336.                 
  5337.                 {
  5338.                 TempODTransform tempXForm = printFrame->AcquireInternalTransform(ev, kODNULL);
  5339.                 sprintf(splat, "  intXForm:  [%d]", (tempXForm->GetRefCount(ev) - 1));
  5340.                 MoveTo( 4, vertical+=12 );
  5341.                 DrawText( &splat, 0, strlen(splat) );
  5342.                 }
  5343.                 
  5344.                 sprintf(splat, "facet: <%p>", facet);
  5345.                 MoveTo( 4, vertical+=12 );
  5346.                 DrawText( &splat, 0, strlen(splat) );
  5347.                 
  5348.                 {
  5349.                 TempODShape tempShape = facet->AcquireClipShape(ev, kODNULL);
  5350.                 sprintf(splat, "  clipShape: [%d]", (tempShape->GetRefCount(ev) - 1));
  5351.                 MoveTo( 4, vertical+=12 );
  5352.                 DrawText( &splat, 0, strlen(splat) );
  5353.                 }
  5354.                 
  5355.                 {
  5356.                 TempODShape tempShape = facet->AcquireActiveShape(ev, kODNULL);
  5357.                 sprintf(splat, "  actvShape: [%d]", (tempShape->GetRefCount(ev) - 1));
  5358.                 MoveTo( 4, vertical+=12 );
  5359.                 DrawText( &splat, 0, strlen(splat) );
  5360.                 }
  5361.                 
  5362.                 {
  5363.                 TempODTransform tempXForm = facet->AcquireExternalTransform(ev, kODNULL);
  5364.                 sprintf(splat, "  extXForm:  [%d]", (tempXForm->GetRefCount(ev) - 1));
  5365.                 MoveTo( 4, vertical+=12 );
  5366.                 DrawText( &splat, 0, strlen(splat) );
  5367.                 }
  5368.  
  5369.                 ODDraft* draft = somSelf->GetStorageUnit(ev)->GetDraft(ev);
  5370.                 // <eeh> please don't remove ID until it shows up in part/frame info dialog
  5371.                 ODFrame* frame = facet->GetFrame(ev);
  5372.                 ODPersistentObjectID id =
  5373.                  (frame->GetStorageUnit(ev) != kODNULL) ?
  5374.                  draft->GetPersistentObjectID( ev,
  5375.                         (ODPersistentObject*)frame, kODFrameObject)        :
  5376.                  frame->GetID(ev);
  5377.                 
  5378.                 sprintf(splat, "ID:    <%d>", id);
  5379.                 MoveTo( 4, vertical+=12 );
  5380.                 DrawText( &splat, 0, strlen(splat) );
  5381.  
  5382.                 if ( facet->GetFrame(ev)->IsRoot(ev) )
  5383.                 {
  5384.                     sprintf(splat, "draft: <%p> [%d]", draft, draft->GetRefCount(ev));
  5385.                     MoveTo( 4, vertical+=12 );
  5386.                     DrawText( &splat, 0, strlen(splat) );
  5387.                 }
  5388.                 
  5389.                 TextSize(12);
  5390.                 ODIText* iText = ODGetComments( ev, facet->GetFrame(ev), kODNULL );
  5391.                 if (iText != kODNULL)
  5392.                 {
  5393.                     MoveTo( 4, vertical+=16 );
  5394.                     DrawText(GetITextPtr(iText), 0, GetITextStringLength(iText) );
  5395.                     DisposeIText(iText);
  5396.                 }
  5397.                 TextSize(9);
  5398.  
  5399.                 
  5400.                 ODFacet* child = kODNULL;
  5401.                 ODFacetIterator* facets = facet->CreateFacetIterator(ev, kODChildrenOnly, kODFrontToBack);
  5402.                 THROW_IF_NULL(facets);
  5403.                 for ( child = facets->First(ev); facets->IsNotComplete(ev); child = facets->Next(ev) )
  5404.                 {
  5405.                     TempODTransform txf = child->AcquireExternalTransform(ev, kODNULL);
  5406.                     Point bob = txf->GetQDOffset(ev);
  5407.                     
  5408.                     TempODShape tfs = child->GetFrame(ev)->AcquireFrameShape(ev, kODNULL);
  5409.                     RgnHandle obo = tfs->GetQDRegion(ev);
  5410.                     bob.v += (**obo).rgnBBox.bottom;
  5411.                 
  5412.                     ODFrame* childFrame = child->GetFrame(ev);
  5413.                     ODPart* childPart = childFrame->AcquirePart(ev);
  5414.                     sprintf(splat, "part:  <%p> [%d]", childPart, (childPart->GetRefCount(ev) - 1));
  5415.                     MoveTo( bob.h, bob.v+=12 );
  5416.                     DrawText( &splat, 0, strlen(splat) );
  5417.                     ODReleaseObject(ev, childPart);
  5418.                     
  5419.                     sprintf(splat, "frame: <%p> [%d]", childFrame, childFrame->GetRefCount(ev));
  5420.                     MoveTo( bob.h, bob.v+=12 );
  5421.                     DrawText( &splat, 0, strlen(splat) );
  5422.                     
  5423.                     {
  5424.                     TempODShape tempShape = childFrame->AcquireFrameShape(ev, kODNULL);
  5425.                     sprintf(splat, "  framShape: [%d]", (tempShape->GetRefCount(ev) - 2));
  5426.                     MoveTo( bob.h, bob.v+=12 );
  5427.                     DrawText( &splat, 0, strlen(splat) );
  5428.                     }
  5429.                     
  5430.                     {
  5431.                     TempODShape tempShape = childFrame->AcquireUsedShape(ev, kODNULL);
  5432.                     sprintf(splat, "  usedShape: [%d]", (tempShape->GetRefCount(ev) - 1));
  5433.                     MoveTo( bob.h, bob.v+=12 );
  5434.                     DrawText( &splat, 0, strlen(splat) );
  5435.                     }
  5436.                     
  5437.                     {
  5438.                     TempODTransform tempXForm = childFrame->AcquireInternalTransform(ev, kODNULL);
  5439.                     sprintf(splat, "  intXForm:  [%d]", (tempXForm->GetRefCount(ev) - 1));
  5440.                     MoveTo( bob.h, bob.v+=12 );
  5441.                     DrawText( &splat, 0, strlen(splat) );
  5442.                     }
  5443.                     
  5444.                     sprintf(splat, "facet: <%p>", child);
  5445.                     MoveTo( bob.h, bob.v+=12 );
  5446.                     DrawText( &splat, 0, strlen(splat) );
  5447.                     
  5448.                     {
  5449.                     TempODShape tempShape = child->AcquireClipShape(ev, kODNULL);
  5450.                     sprintf(splat, "  clipShape: [%d]", (tempShape->GetRefCount(ev) - 1));
  5451.                     MoveTo( bob.h, bob.v+=12 );
  5452.                     DrawText( &splat, 0, strlen(splat) );
  5453.                     }
  5454.                     
  5455.                     {
  5456.                     TempODShape tempShape = child->AcquireActiveShape(ev, kODNULL);
  5457.                     sprintf(splat, "  actvShape: [%d]", (tempShape->GetRefCount(ev) - 1));
  5458.                     MoveTo( bob.h, bob.v+=12 );
  5459.                     DrawText( &splat, 0, strlen(splat) );
  5460.                     }
  5461.                     
  5462.                     {
  5463.                     TempODTransform tempXForm = child->AcquireExternalTransform(ev, kODNULL);
  5464.                     sprintf(splat, "  extXForm:  [%d]", (tempXForm->GetRefCount(ev) - 2));
  5465.                     MoveTo( bob.h, bob.v+=12 );
  5466.                     DrawText( &splat, 0, strlen(splat) );
  5467.                     }
  5468.                     
  5469.                 }
  5470.                 ODDeleteObject(facets);
  5471. #endif            
  5472.                 
  5473.                 // no intrinsic contents, so just highlight the selection
  5474.                 
  5475.                 ODFrame* activeFrame = _fSession->GetArbitrator(ev)->AcquireFocusOwner(ev, _fSelectionFocus);
  5476.                 if (displayFrame == activeFrame)
  5477.                 {    // drawing active frame - highlight selection
  5478.                     somSelf->HighlightSelection(ev);
  5479.                 }
  5480.                 else
  5481.                 {    // drawing inactive frame - do nothing for now
  5482.                 }
  5483.                 ODReleaseObject(ev, activeFrame);
  5484.             }
  5485.         }
  5486.     }
  5487.     else
  5488.     {
  5489.         // !!! signal error: invalid frame
  5490.     }
  5491.  
  5492.     SOM_CATCH_ALL_ENDTRY
  5493. }
  5494.  
  5495. SOM_Scope void  SOMLINK AppleTest_ContainerCanvasUpdated(AppleTest_Container *somSelf, Environment *ev,
  5496.         ODCanvas* canvas)
  5497. {
  5498.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  5499.     AppleTest_ContainerMethodDebug("AppleTest_Container","CanvasUpdated");
  5500.  
  5501.     SOM_TRY
  5502.  
  5503.     ODUnused(canvas);
  5504.  
  5505.     SOM_CATCH_ALL_ENDTRY
  5506. }
  5507.  
  5508. SOM_Scope void  SOMLINK AppleTest_ContainerHighlightChanged(AppleTest_Container *somSelf, Environment *ev,
  5509.         ODFacet* facet)
  5510. {
  5511.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  5512.     AppleTest_ContainerMethodDebug("AppleTest_Container","HighlightChanged");
  5513.  
  5514.     SOM_TRY
  5515.  
  5516.     ODUnused(facet);
  5517.  
  5518.     SOM_CATCH_ALL_ENDTRY
  5519. }
  5520.  
  5521. SOM_Scope ODULong  SOMLINK AppleTest_ContainerGetPrintResolution(AppleTest_Container *somSelf, Environment *ev,
  5522.         ODFrame* frame)
  5523. {
  5524.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  5525.     AppleTest_ContainerMethodDebug("AppleTest_Container","GetPrintResolution");
  5526.  
  5527.     SOM_TRY
  5528.  
  5529.     ODUnused(frame);
  5530.  
  5531.     return 0;
  5532.  
  5533.     SOM_CATCH_ALL_ENDTRY
  5534.     return 0;
  5535. }
  5536.  
  5537. SOM_Scope ODLinkSource*  SOMLINK AppleTest_ContainerCreateLink(AppleTest_Container *somSelf, Environment *ev,
  5538.         ODByteArray* data)
  5539. {
  5540.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  5541.     AppleTest_ContainerMethodDebug("AppleTest_Container","CreateLink");
  5542.  
  5543.     SOM_TRY
  5544.  
  5545.     ODUnused(data);
  5546.  
  5547.     return nil;
  5548.  
  5549.     SOM_CATCH_ALL_ENDTRY
  5550.     return kODNULL;
  5551. }
  5552.  
  5553. SOM_Scope void  SOMLINK AppleTest_ContainerLinkUpdated(AppleTest_Container *somSelf, Environment *ev,
  5554.         ODLink* updatedLink,
  5555.         ODUpdateID change)
  5556. {
  5557.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  5558.     AppleTest_ContainerMethodDebug("AppleTest_Container","LinkUpdated");
  5559.  
  5560.     SOM_TRY
  5561.  
  5562.     ODUnused(updatedLink);
  5563.     ODUnused(change);
  5564.  
  5565.     SOM_CATCH_ALL_ENDTRY
  5566. }
  5567.  
  5568. SOM_Scope void  SOMLINK AppleTest_ContainerRevealLink(AppleTest_Container *somSelf, Environment *ev,
  5569.         ODLinkSource* linkSource)
  5570. {
  5571.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  5572.     AppleTest_ContainerMethodDebug("AppleTest_Container","RevealLink");
  5573.  
  5574.     SOM_TRY
  5575.  
  5576.     ODUnused(linkSource);
  5577.  
  5578.     SOM_CATCH_ALL_ENDTRY
  5579. }
  5580.  
  5581. SOM_Scope void  SOMLINK AppleTest_ContainerEmbeddedFrameUpdated(AppleTest_Container *somSelf, Environment *ev,
  5582.         ODFrame* frame,
  5583.         ODUpdateID change)
  5584. {
  5585.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  5586.     AppleTest_ContainerMethodDebug("AppleTest_Container","EmbeddedFrameUpdated");
  5587.  
  5588.     SOM_TRY
  5589.  
  5590.     ODUnused(change);
  5591.     ODUnused(frame);
  5592.  
  5593.     SOM_CATCH_ALL_ENDTRY
  5594. }
  5595.  
  5596. SOM_Scope void  SOMLINK AppleTest_ContainerLinkStatusChanged(AppleTest_Container *somSelf, Environment *ev,
  5597.         ODFrame* frame)
  5598. {
  5599.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  5600.     AppleTest_ContainerMethodDebug("AppleTest_Container","LinkStatusChanged");
  5601.  
  5602.     SOM_TRY
  5603.  
  5604.     ODUnused(frame);
  5605.  
  5606.     SOM_CATCH_ALL_ENDTRY
  5607. }
  5608.  
  5609. SOM_Scope ODBoolean  SOMLINK AppleTest_ContainerBeginRelinquishFocus(AppleTest_Container *somSelf, Environment *ev,
  5610.         ODTypeToken focus,
  5611.         ODFrame* ownerFrame,
  5612.         ODFrame* proposedFrame)
  5613. {
  5614.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  5615.     AppleTest_ContainerMethodDebug("AppleTest_Container","BeginRelinquishFocus");
  5616.  
  5617.     SOM_TRY
  5618.  
  5619.     ODUnused(focus);
  5620.     ODUnused(ownerFrame);
  5621.     ODUnused(proposedFrame);
  5622.  
  5623.     return kODTrue;
  5624.  
  5625.     SOM_CATCH_ALL_ENDTRY
  5626.     return kODFalse;
  5627. }
  5628.  
  5629. SOM_Scope void  SOMLINK AppleTest_ContainerCommitRelinquishFocus(AppleTest_Container *somSelf, Environment *ev,
  5630.         ODTypeToken focus,
  5631.         ODFrame* ownerFrame,
  5632.         ODFrame* proposedFrame)
  5633. {
  5634.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  5635.     AppleTest_ContainerMethodDebug("AppleTest_Container","CommitRelinquishFocus");
  5636.  
  5637.     SOM_TRY
  5638.  
  5639.     ODUnused(proposedFrame);
  5640.  
  5641.     somSelf->FocusLost(ev, focus, ownerFrame);
  5642.     if (focus != _fClipboardFocus)
  5643.         somSelf->HidePalette(ev);
  5644.  
  5645.     SOM_CATCH_ALL_ENDTRY
  5646. }
  5647.  
  5648. SOM_Scope void  SOMLINK AppleTest_ContainerAbortRelinquishFocus(AppleTest_Container *somSelf, Environment *ev,
  5649.         ODTypeToken focus,
  5650.         ODFrame* ownerFrame,
  5651.         ODFrame* proposedFrame)
  5652. {
  5653.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  5654.     AppleTest_ContainerMethodDebug("AppleTest_Container","AbortRelinquishFocus");
  5655.  
  5656.     SOM_TRY
  5657.  
  5658.     ODUnused(focus);
  5659.     ODUnused(ownerFrame);
  5660.     ODUnused(proposedFrame);
  5661.  
  5662.     SOM_CATCH_ALL_ENDTRY
  5663. }
  5664.  
  5665. SOM_Scope void  SOMLINK AppleTest_ContainerFocusAcquired(AppleTest_Container *somSelf, Environment *ev,
  5666.         ODTypeToken focus,
  5667.         ODFrame* ownerFrame)
  5668. {
  5669.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  5670.     AppleTest_ContainerMethodDebug("AppleTest_Container","FocusAcquired");
  5671.  
  5672.     SOM_TRY
  5673.  
  5674.     Proxy* sp = kODNULL;
  5675.     
  5676.     if (focus == _fSelectionFocus) 
  5677.     {
  5678.         PartInfoRec* pInfo = (PartInfoRec*) ownerFrame->GetPartInfo(ev);
  5679.         pInfo->fIsActive = kODTrue;
  5680.         
  5681.         if ( _fSelection )
  5682.             sp = (Proxy*) _fSelection->First();
  5683.         if ( sp )
  5684.         {
  5685.             somSelf->CreateProxySelectionBorder(ev, sp);
  5686.             somSelf->ClipEmbeddedFrames(ev, ownerFrame);
  5687.         }
  5688.         
  5689.         somSelf->ShowPalette(ev);
  5690.     }
  5691.     else if (focus == _fMenuFocus) 
  5692.         somSelf->InstallMenus(ev, ownerFrame);
  5693.  
  5694.     SOM_CATCH_ALL_ENDTRY
  5695. }
  5696.  
  5697. SOM_Scope void  SOMLINK AppleTest_ContainerFocusLost(AppleTest_Container *somSelf, Environment *ev,
  5698.         ODTypeToken focus,
  5699.         ODFrame* ownerFrame)
  5700. {
  5701.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  5702.     AppleTest_ContainerMethodDebug("AppleTest_Container","FocusLost");
  5703.  
  5704.     SOM_TRY
  5705.  
  5706.     if (focus == _fSelectionFocus) 
  5707.     {
  5708.         PartInfoRec* pInfo = (PartInfoRec*) ownerFrame->GetPartInfo(ev);
  5709.         pInfo->fIsActive = kODFalse;
  5710.         somSelf->InvalidateSelection(ev, ownerFrame);
  5711.         somSelf->EmptySelection(ev);
  5712.         SetEmptyRgn(_fSelectRgn);
  5713.         SetEmptyRgn(_fCornerHandleRgn);
  5714.         SetEmptyRgn(_fEdgeHandleRgn);
  5715.         somSelf->ClipEmbeddedFrames(ev, ownerFrame);
  5716.         
  5717.         somSelf->HidePalette(ev);
  5718.     }
  5719.     else if (focus == _fMenuFocus)
  5720.     {
  5721.         somSelf->RemoveMenus(ev, ownerFrame);
  5722.     }
  5723.  
  5724.     SOM_CATCH_ALL_ENDTRY
  5725. }
  5726.  
  5727. SOM_Scope void  SOMLINK AppleTest_ContainerCloneInto(AppleTest_Container *somSelf, Environment *ev,
  5728.         ODDraftKey key,
  5729.         ODStorageUnit* toSU,
  5730.         ODFrame* scopeFrame)
  5731. {
  5732.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  5733.     AppleTest_ContainerMethodDebug("AppleTest_Container","CloneInto");
  5734.  
  5735.     SOM_TRY
  5736.  
  5737.     parent_CloneInto(somSelf,ev,key,toSU,scopeFrame);
  5738.  
  5739.     if ( !toSU->Exists(ev, kODPropContents, kKindTestDraw, 0) )
  5740.     {
  5741.         // $$$$$ For the MacTech seed CD, don't promise content so linked content
  5742.         // is cloned correctly.
  5743. #ifndef BETASEEDMODS
  5744.         if ( toSU->Exists(ev, kODPropContentFrame, kODWeakStorageUnitRef, 0) )
  5745.         {
  5746.             // This part is being cloned as a single embedded part, so promise our content.
  5747. // #if ODDebug
  5748. //            somPrintf("Draw %d::CloneInto: Promising content\n", somSelf->GetID(ev));
  5749. // #endif
  5750.             if ( !toSU->Exists(ev, kODPropContents, kODNULL, 0) )
  5751.                 toSU->AddProperty(ev, kODPropContents);
  5752.             // $$$$$ Should store the scopeFrame as the promise value so FulFill promise
  5753.             // can enforce scope restrictions correctly.
  5754.             ODSShort dummy = 0;
  5755.             StorageUnitSetPromiseValue(toSU, ev, kKindTestDraw, 0, 0, kODNULL, somSelf);
  5756.         }
  5757.         else
  5758. #endif
  5759.         {
  5760. #if ODDebug
  5761.             somPrintf("Draw %d::CloneInto: Cloning content to %d %d\n", somSelf->GetID(ev), toSU, scopeFrame);
  5762. #endif
  5763.             TempODStorageUnit testDrawContentSU = toSU->GetDraft(ev)->CreateStorageUnit(ev);
  5764.             somSelf->CloneTestDrawContent(ev, key, testDrawContentSU, scopeFrame);
  5765.             
  5766.             ODSetStrongSURefProp(ev, toSU, kODPropContents, kKindTestDraw, testDrawContentSU->GetID(ev));
  5767. #if ODDebug
  5768.             somPrintf("Draw %d::CloneInto: Cloning Done\n", somSelf->GetID(ev));
  5769. #endif
  5770.         }
  5771.     }
  5772.  
  5773.     SOM_CATCH_ALL_ENDTRY
  5774. }
  5775.  
  5776. //------------------------------------------------------------------------------
  5777. // Draw: CloneTestDrawContent
  5778. //------------------------------------------------------------------------------
  5779. SOM_Scope void  SOMLINK AppleTest_ContainerCloneTestDrawContent(AppleTest_Container *somSelf, Environment *ev,
  5780.         ODDraftKey        key,
  5781.         ODStorageUnit*    toSU,
  5782.         ODFrame*        scopeFrame)
  5783. {
  5784.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  5785.     AppleTest_ContainerMethodDebug("AppleTest_Container","CloneTestDrawContent");
  5786.  
  5787.     SOM_TRY
  5788.     
  5789. #if ODDebug
  5790.     somPrintf("Draw %d::CloneTestDrawContent: Cloning content\n", somSelf->GetID(ev));
  5791. #endif
  5792.  
  5793.     ODSetBooleanProp(ev, toSU, kPropScriptingOn, kODBoolean, _fScriptingOn);
  5794.     
  5795.     ODDraft* fromDraft = somSelf->GetStorageUnit(ev)->GetDraft(ev);
  5796.     ODDraft* toDraft = toSU->GetDraft(ev);
  5797.     
  5798.     ODStorageUnitRef aSURef;
  5799.     ODULong offset;
  5800.     ODFrame* frame;
  5801.     Proxy* proxy;
  5802.     OrderedCollectionIterator aIter(_fDisplayFrames);
  5803.     OrderedCollectionIterator cIter(_fContents);
  5804.     Point xform;
  5805.     ODID scopeFrameID = ( scopeFrame ? scopeFrame->GetID(ev) : 0 );
  5806.  
  5807.     ODSUAddPropValue(ev, toSU, kODPropDisplayFrames, kODWeakStorageUnitRef);
  5808.  
  5809.     offset = 0;
  5810.     for (frame = (ODFrame*)aIter.First(); aIter.IsNotComplete();
  5811.             frame = (ODFrame*)aIter.Next(), offset+=sizeof(ODStorageUnitRef))
  5812.     {
  5813.         // $$$$$ Don't copy display frames unless they're in scope; 
  5814.         // Currently, this part supports only one display frame
  5815.         ODID toFrameID = fromDraft->WeakClone(ev, key, frame->GetID(ev), 0, scopeFrameID);
  5816.         toSU->GetWeakStorageUnitRef(ev, toFrameID, aSURef);
  5817.         toSU->SetOffset(ev, offset);
  5818.         StorageUnitSetValue(toSU, ev, sizeof(ODStorageUnitRef), aSURef);
  5819.     }
  5820.  
  5821.     ODSetULongProp(ev, toSU, kODPropFrameGroup, kODULong, _fFrameGroupIDCounter);
  5822.  
  5823.     ODSUAddPropValue(ev, toSU, kODPropEmbeddedFrames, kODStrongStorageUnitRef);
  5824.     offset = 0;
  5825.     for (proxy = (Proxy*)cIter.First();
  5826.             cIter.IsNotComplete(); 
  5827.             proxy = (Proxy*)cIter.Next())
  5828.     {
  5829. #if ODDebug
  5830.     somPrintf("Draw %d::CloneTestDrawContent: Clone Proxy: %d\n", somSelf->GetID(ev), proxy->frame->GetID(ev));
  5831. #endif
  5832.         ODID id = proxy->frame->GetID(ev);
  5833.         ODID toFrameID = fromDraft->Clone(ev, key, id, 0, id);
  5834.         toSU->GetStrongStorageUnitRef(ev, toFrameID, aSURef);
  5835.         toSU->SetOffset(ev, offset);
  5836.         StorageUnitSetValue(toSU, ev, sizeof(ODStorageUnitRef), aSURef);
  5837.         offset += sizeof(ODStorageUnitRef);
  5838.         
  5839.         xform = proxy->transform->GetQDOffset(ev);
  5840.         toSU->SetOffset(ev, offset);
  5841.         StorageUnitSetValue(toSU, ev, sizeof(ODPlatformTransform), (ODValue)&xform);
  5842.         offset += sizeof(Point);
  5843.     }
  5844.  
  5845. #if ODDebug
  5846.     somPrintf("Draw %d::CloneTestDrawContent: Done\n", somSelf->GetID(ev));
  5847. #endif
  5848.     
  5849.     SOM_CATCH_ALL
  5850.         PRINT("Draw %d::CloneTestDrawContent: Exception caught\n", somSelf->GetID(ev));
  5851.     SOM_ENDTRY
  5852. }
  5853.  
  5854. /*
  5855.  * SOM_Scope void  SOMLINK AppleTest_ContainerExternalizeKinds(AppleTest_Container *somSelf, Environment *ev,
  5856.  *         ODTypeSet* kindset)
  5857.  */
  5858.  
  5859. /*
  5860.  * The prototype for AppleTest_ContainerExternalizeKinds was replaced by the following prototype:
  5861.  */
  5862. SOM_Scope void  SOMLINK AppleTest_ContainerExternalizeKinds(AppleTest_Container *somSelf, Environment *ev,
  5863.         ODTypeList* kindset)
  5864. {
  5865.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  5866.     AppleTest_ContainerMethodDebug("AppleTest_Container","ExternalizeKinds");
  5867.  
  5868.     SOM_TRY
  5869.  
  5870.     ODUnused(kindset);
  5871.     somSelf->Externalize(ev);
  5872.  
  5873.     SOM_CATCH_ALL_ENDTRY
  5874. }
  5875.  
  5876. SOM_Scope void  SOMLINK AppleTest_ContainerExternalize(AppleTest_Container *somSelf, Environment *ev)
  5877. {
  5878.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  5879.     AppleTest_ContainerMethodDebug("AppleTest_Container","Externalize");
  5880.  
  5881.     SOM_TRY
  5882.  
  5883.     parent_Externalize(somSelf,ev);
  5884. //    UpdateModificationInfo(ev, somSelf->GetStorageUnit(ev));
  5885.  
  5886. //    SimplePart::Externalize();
  5887. //  since SimplePart has no Externalize method, I assume this just calls
  5888. //  the same code as AppleTest_Container_parent_ODPart_Externalize.  So ignore.
  5889.     
  5890.     ODStorageUnit* su = _fTestDrawSU;
  5891.     ODStorageUnitRef aSURef;
  5892.     ODULong offset;
  5893.     ODFrame* frame;
  5894.     Proxy* proxy;
  5895.     OrderedCollectionIterator aIter(_fDisplayFrames);
  5896. //    OrderedCollectionIterator bIter(_fEmbeddedFrames);
  5897.     OrderedCollectionIterator cIter(_fContents);
  5898.     Point xform;
  5899.  
  5900.     ODSetBooleanProp(ev, su, kPropScriptingOn,kODBoolean, _fScriptingOn);
  5901.  
  5902.     ODSURemoveProperty(ev, su, kODPropDisplayFrames);
  5903.     ODSUAddPropValue(ev, su, kODPropDisplayFrames, kODWeakStorageUnitRef);
  5904.  
  5905.     offset = 0;
  5906.     for (frame = (ODFrame*)aIter.First(); aIter.IsNotComplete();
  5907.             frame = (ODFrame*)aIter.Next(), offset+=sizeof(ODStorageUnitRef))
  5908.     {
  5909.         frame->Externalize(ev);
  5910.         su->GetWeakStorageUnitRef(ev, frame->GetStorageUnit(ev)->GetID(ev), aSURef);
  5911.         su->SetOffset(ev, offset);
  5912.         StorageUnitSetValue(su, ev, sizeof(ODStorageUnitRef), aSURef);
  5913.     }
  5914.  
  5915.     ODSetULongProp(ev, su, kODPropFrameGroup, kODULong, _fFrameGroupIDCounter);
  5916.     
  5917.     ODSURemoveProperty(ev, su, kODPropEmbeddedFrames);
  5918.     ODSUAddPropValue(ev, su, kODPropEmbeddedFrames, kODStrongStorageUnitRef);
  5919.     // $$$$$ should be something DrawPart specific, not kODStrongStorageUnitRef
  5920.     // since it is storing StorageUnitRefs and xforms in the same stream.
  5921.  
  5922.     offset = 0;
  5923.     for (proxy = (Proxy*)cIter.First();
  5924.             cIter.IsNotComplete(); 
  5925.             proxy = (Proxy*)cIter.Next())
  5926.     {
  5927.         proxy->frame->Externalize(ev);
  5928.         su->GetStrongStorageUnitRef(ev, proxy->frame->GetStorageUnit(ev)->GetID(ev), aSURef);
  5929.         su->SetOffset(ev, offset);
  5930.         StorageUnitSetValue(su, ev, sizeof(ODStorageUnitRef), aSURef);
  5931.         offset += sizeof(ODStorageUnitRef);
  5932.         
  5933.         xform = proxy->transform->GetQDOffset(ev);
  5934.         su->SetOffset(ev, offset);
  5935.         StorageUnitSetValue(su, ev, sizeof(ODPlatformTransform), (ODValue)&xform);
  5936.         offset += sizeof(Point);
  5937.     }
  5938.  
  5939.     su = somSelf->GetStorageUnit(ev);
  5940.     ODSetStrongSURefProp(ev, su, kODPropContents,kKindTestDraw, _fTestDrawSU->GetID(ev));
  5941.     
  5942.     SOM_CATCH_ALL_ENDTRY
  5943. }
  5944.  
  5945. SOM_Scope void  SOMLINK AppleTest_ContainerChangeKind(AppleTest_Container *somSelf, Environment *ev,
  5946.         ODType kind)
  5947. {
  5948.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  5949.     AppleTest_ContainerMethodDebug("AppleTest_Container","ChangeKind");
  5950.  
  5951.     SOM_TRY
  5952.  
  5953.     ODUnused(kind);
  5954.  
  5955.     SOM_CATCH_ALL_ENDTRY
  5956. }
  5957.  
  5958. SOM_Scope ODBoolean  SOMLINK AppleTest_ContainerHandleEvent(AppleTest_Container *somSelf, Environment *ev,
  5959.         ODEventData* event,
  5960.         ODFrame* frame,
  5961.         ODFacet* facet,
  5962.         ODEventInfo* eventInfo)
  5963. {
  5964.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  5965.     AppleTest_ContainerMethodDebug("AppleTest_Container","HandleEvent");
  5966.  
  5967.     SOM_TRY
  5968.  
  5969.     Point windowPoint;
  5970.     GrafPtr curPort;
  5971.     ODBoolean handled = kODFalse;
  5972.     
  5973. #if ODDebug
  5974.     // somPrintf("Draw %d::HandleEvent in frame %d, facet %x\n", somSelf->GetID(ev), 
  5975.     //    (frame ? frame->GetID(ev) : 0), facet);
  5976. #endif
  5977.  
  5978.     switch (event->what)
  5979.     {
  5980.         case nullEvent:
  5981.             break;
  5982.         
  5983.         case mouseDown:
  5984.         case kODEvtBGMouseDown:
  5985.             if (_fDrawingLines)
  5986.             {
  5987.                 somSelf->StopDrawingLines(ev, frame);
  5988.                 WindowPtr platformWindow = kODNULL;
  5989.                 short         partCode;
  5990.                 partCode = FindWindow ( event->where, &platformWindow );
  5991.                 if (partCode == inMenuBar)
  5992.                     _fSession->GetDispatcher(ev)->Dispatch(ev, event);
  5993.             }
  5994.  
  5995.             {
  5996.                 windowPoint = event->where;
  5997.                 GetPort(&curPort);
  5998.                 SetPort(facet->GetWindow(ev)->GetPlatformWindow(ev));
  5999.                 SetOrigin(0,0);
  6000.                 GlobalToLocal(&windowPoint);
  6001.                 ODPoint windowODPoint(windowPoint);
  6002.  
  6003.                 if( event->what==mouseDown )
  6004.                     handled = somSelf->HandleMouseDown(ev, facet, &windowODPoint, event);
  6005.                 else
  6006.                     handled = somSelf->HandleBGMouseDown(ev, facet, &windowODPoint, event);
  6007.  
  6008.                 SetPort(curPort);
  6009.             }
  6010.             break;
  6011.             
  6012.         case kODEvtWindow: 
  6013.             {
  6014.                 if (_fDrawingLines)
  6015.                     somSelf->StopDrawingLines(ev, frame);
  6016.                 switch (event->message)
  6017.                 {
  6018.                     case inGoAway:
  6019.                         ODWindow*    window = facet->GetWindow(ev);
  6020.                         if (window == _fPalette) {
  6021.                             somSelf->HidePalette(ev);
  6022.                             _fPaletteUp = kODFalse;
  6023.                         }
  6024.                         break;
  6025.                     case inZoomIn:
  6026.                     case inZoomOut:
  6027.                         SysBeep(2); 
  6028.                         handled = kODTrue;
  6029.                         break;
  6030.                     default:
  6031.                         break;
  6032.                 }
  6033.             }
  6034.             break;
  6035.         
  6036.         case mouseUp:
  6037. #if defined(ODDebug) && ODDebugActivates
  6038.         somPrintf("Draw %d::Mouse Up: Calling IsActive\n", somSelf->GetID(ev));
  6039. #endif
  6040.             if (!facet->GetWindow(ev)->IsActive(ev))
  6041.             {
  6042. #if defined(ODDebug) && ODDebugActivates
  6043.         somPrintf("Draw %d::Mouse Up: Calling Select\n", somSelf->GetID(ev));
  6044. #endif
  6045.                 facet->GetWindow(ev)->Select(ev);
  6046.             }
  6047.             else
  6048.                 somSelf->ActivateFrame(ev, facet->GetFrame(ev));
  6049.             handled = kODTrue;
  6050.             break;
  6051.             
  6052.         case keyDown:
  6053.         case autoKey:
  6054.             handled = somSelf->HandleKeyDown(ev, frame, event);
  6055.             break;
  6056.     
  6057.         case activateEvt:
  6058.             if (_fDrawingLines)
  6059.                 somSelf->StopDrawingLines(ev, frame);
  6060.             handled = true; // actually ignored by dispatcher
  6061.             if ((event->modifiers & activeFlag) != 0)
  6062.                 somSelf->ActivatingWindow(ev, frame);
  6063.             else
  6064.                 somSelf->DeActivatingWindow(ev, frame);
  6065.             break;
  6066.         
  6067.         case keyUp:
  6068.             break;
  6069.                         
  6070.         case osEvt:
  6071.             {
  6072.                 unsigned char     typeOSEvent;
  6073.                 
  6074.                 // • Is it a multifinder event?
  6075.                 typeOSEvent = (unsigned char) (event->message >> 24) & 0x00FF;
  6076.                 
  6077.                 // • Switch on the type of OSEvent that occurred, high byte of message is event type
  6078.                 switch (typeOSEvent) 
  6079.                 {     
  6080.                     case kMouseMovedMessage:
  6081.                         break;
  6082.                         
  6083.                     case kSuspendResumeMessage:
  6084.                         {
  6085.                             if (_fDrawingLines)
  6086.                                 somSelf->StopDrawingLines(ev, frame);
  6087.                             const short kResumeMask = 0x01;    // High byte suspend/resume event 
  6088.                             ODBoolean    goingToBackground = (event->message & kResumeMask) == 0;
  6089.                             ODWindow*    window = facet->GetWindow(ev);
  6090.                             if (window && window != _fPalette) 
  6091.                             {
  6092.                                 if (goingToBackground)
  6093.                                 {
  6094. #if ODDebug
  6095.     // somPrintf("DrawPart Suspend Event\n");
  6096. #endif
  6097.                                     if (_fPalette && _fPalette->IsShown(ev))
  6098.                                     {
  6099.                                         _fPaletteWasShown = kODTrue;
  6100.                                         somSelf->HidePalette(ev);
  6101.                                         _fPaletteUp = kODFalse;
  6102.                                     }
  6103.                                     else
  6104.                                         _fPaletteWasShown = kODFalse;
  6105.                                 }
  6106.                                 else
  6107.                                 {
  6108. #if ODDebug
  6109.     // somPrintf("DrawPart Resume Event\n");
  6110. #endif
  6111.                                     if (_fPaletteWasShown)
  6112.                                     {
  6113.                                         _fPaletteUp = kODTrue;
  6114.                                         somSelf->ShowPalette(ev);
  6115.                                     }
  6116.                                 }
  6117.                             }
  6118.                                 
  6119.                         }
  6120.                         break;
  6121.                 }
  6122.             }
  6123.  
  6124.             break;
  6125.     
  6126.         case kHighLevelEvent:
  6127.             break;
  6128.  
  6129.         case kODEvtMenu:
  6130.             if (_fDrawingLines)
  6131.                 somSelf->StopDrawingLines(ev, frame);
  6132.             else
  6133.             handled = somSelf->HandleMenuEvent(ev, frame, event);
  6134.             break;
  6135.             
  6136.         case kODEvtMouseDownEmbedded:
  6137.         case kODEvtBGMouseDownEmbedded:
  6138.             {
  6139. //#if ODDebug
  6140. //    somPrintf("Draw %d::MouseDownInEmbedded in frame %d, facet %x, embedded frame %d, embedded facet %x\n", somSelf->GetID(ev), 
  6141. //        (frame ? frame->GetID(ev) : 0), facet, (eventInfo->embeddedFrame ? eventInfo->embeddedFrame->GetID(ev) : 0), eventInfo->embeddedFacet);
  6142. //#endif
  6143.  
  6144.                 // $$$$$ Note: Could use eventInfo->where, which is in frame coordinates
  6145.                 windowPoint = event->where;
  6146.                 GetPort(&curPort);
  6147.                 SetPort(facet->GetWindow(ev)->GetPlatformWindow(ev));
  6148.                 SetOrigin(0,0);
  6149.                 GlobalToLocal(&windowPoint);
  6150.                 ODPoint ODWindowPoint (windowPoint);
  6151.                 handled = somSelf->HandleMouseDownInEmbeddedFrame(ev, facet, 
  6152.                                         eventInfo->embeddedFacet,
  6153.                                         &ODWindowPoint, event);
  6154.                 SetPort(curPort);
  6155.             }
  6156.             break;
  6157.         
  6158.         case kODEvtMouseDownBorder:
  6159.             {
  6160.                 if (!facet->GetWindow(ev)->IsActive(ev))
  6161.                     facet->GetWindow(ev)->Select(ev);
  6162.                 else
  6163.                     somSelf->ActivateFrame(ev, facet->GetFrame(ev));
  6164.     
  6165.                 ODSLong savedRefNum;
  6166.                 BeginUsingLibraryResources(savedRefNum);
  6167.                 SetCursor(*GetCursor(284)); // Closed Hand Cursor 
  6168.                 EndUsingLibraryResources(savedRefNum);
  6169.                 
  6170.                 windowPoint = event->where;
  6171.                 GetPort(&curPort);
  6172.                 SetPort(facet->GetWindow(ev)->GetPlatformWindow(ev));
  6173.                 SetOrigin(0,0);
  6174.                 GlobalToLocal(&windowPoint);
  6175.                 ODPoint ODWindowPoint (windowPoint);
  6176.                 handled = somSelf->HandleMouseDownInEmbeddedFrame(ev, facet, 
  6177.                                         eventInfo->embeddedFacet,
  6178.                                         &ODWindowPoint, event);
  6179.                 SetPort(curPort);
  6180.             }
  6181.             break;
  6182.         
  6183.         case kODEvtMouseUpEmbedded:
  6184.             //facet->GetFrame(ev)->SetDragging(ev, kODFalse);
  6185. #if defined(ODDebug) && ODDebugActivates
  6186.         somPrintf("Draw %d::Mouse Down: Calling IsActive\n", somSelf->GetID(ev));
  6187. #endif
  6188.             if (!facet->GetWindow(ev)->IsActive(ev))
  6189.             {
  6190. #if defined(ODDebug) && ODDebugActivates
  6191.         somPrintf("Draw %d::Mouse Down: Calling Select\n", somSelf->GetID(ev));
  6192. #endif
  6193.                 facet->GetWindow(ev)->Select(ev);
  6194.             }
  6195.             else
  6196.                 somSelf->ActivateFrame(ev, facet->GetFrame(ev));
  6197.             handled = kODTrue;
  6198.             break;
  6199.             
  6200.         case kODEvtMouseEnter:
  6201. #if defined(ODDebug) && ODDebugCursor
  6202.     somPrintf("MouseEnter %d %d\n",eventInfo->where.IntX(),eventInfo->where.IntY());
  6203. #endif    
  6204.         case kODEvtMouseWithin:
  6205. #if defined(ODDebug) && ODDebugCursor
  6206.     somPrintf("MouseWithin %d %d\n",eventInfo->where.IntX(),eventInfo->where.IntY());
  6207. #endif
  6208.             {
  6209.                 // Note: ODFacet::ActiveBorderContainsPoint takes frame coordinates
  6210.                 ODBoolean cursorInActiveBorder = kODFalse;
  6211.                 ODArbitrator* fArbitrator = _fSession->GetArbitrator(ev);
  6212.                 ODFrame* activeFrame = fArbitrator->AcquireFocusOwner(ev, _fSelectionFocus);
  6213.                 WASSERTM(activeFrame != kODNULL, "Noone owns the selection focus, i.e. No active frame.");
  6214.                 if (activeFrame) 
  6215.                 {
  6216.                     ODFrameFacetIterator* iter = activeFrame->CreateFacetIterator(ev);
  6217.                     ODReleaseObject(ev, activeFrame);
  6218.                     
  6219.                     ODPoint windowMouse = eventInfo->where;
  6220.                     { TempODTransform windowFrameXForm = facet->AcquireWindowFrameTransform(ev, kODNULL);
  6221.                       windowFrameXForm->TransformPoint(ev, &windowMouse);
  6222.                     }
  6223.                     
  6224.                     if (_fDrawingLines)
  6225.                     {    
  6226.                         CFocus focus(ev, facet);
  6227.  
  6228.                         PenNormal();
  6229.                         MoveTo(gLastPoint.h, gLastPoint.v);
  6230.                         Point qdPt = eventInfo->where.AsQDPoint(); // windowMouse.AsQDPoint();
  6231.                         LineTo(qdPt.h, qdPt.v);
  6232.                         handled = kODTrue;
  6233.                         return handled;
  6234.                     }
  6235.                     
  6236.                     for (ODFacet* facet = iter->First(ev); iter->IsNotComplete(ev);
  6237.                         facet = iter->Next(ev))
  6238.                     {
  6239.                         ODPoint framePoint = windowMouse;
  6240.                         { TempODTransform xForm = facet->AcquireWindowFrameTransform(ev, kODNULL);
  6241.                           xForm->InvertPoint(ev, &framePoint);
  6242.                         }
  6243.                         
  6244.                         if (facet->ActiveBorderContainsPoint(ev,&framePoint,kODNULL))
  6245.                         {
  6246.                             cursorInActiveBorder = kODTrue;
  6247.                             break;
  6248.                         } 
  6249.                     }
  6250.                     ODDeleteObject(iter);
  6251.                 }
  6252.                 if (cursorInActiveBorder)
  6253.                 {
  6254.                     ODSLong savedRefNum;
  6255.                     BeginUsingLibraryResources(savedRefNum);
  6256.                     SetCursor(*GetCursor(283)); // Hand Cursor 
  6257.                     EndUsingLibraryResources(savedRefNum);
  6258.                 }
  6259.                 else
  6260.                     SetCursor(*GetCursor(crossCursor)); // For now. 
  6261.                     
  6262.             }
  6263.             handled = kODTrue;
  6264.             break;
  6265.         case kODEvtMouseLeave:
  6266. #if defined(ODDebug) && ODDebugCursor
  6267.     somPrintf("MouseLeave\n");
  6268. #endif
  6269.             SetCursor(&ODQDGlobals.arrow);
  6270.             handled = kODTrue;
  6271.             break;
  6272.         
  6273.                     
  6274.         default:
  6275.             return kODFalse;
  6276.     }
  6277.     return handled;
  6278.  
  6279.     SOM_CATCH_ALL_ENDTRY
  6280.     return kODFalse;
  6281. }
  6282.  
  6283.  
  6284.  
  6285. SOM_Scope void  SOMLINK AppleTest_ContainerAdjustMenus(AppleTest_Container *somSelf, Environment *ev,
  6286.         ODFrame* frame)
  6287. {
  6288.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  6289.     AppleTest_ContainerMethodDebug("AppleTest_Container","AdjustMenus");
  6290.  
  6291.     SOM_TRY
  6292.     
  6293.     PartInfoRec* pInfo = (PartInfoRec*) frame->GetPartInfo(ev);
  6294.     ODIText* menuItem = kODNULL;
  6295.  
  6296.     // if this frame is the root frame, enable printing.
  6297.     
  6298.     TempODFrame tempFrame = frame->AcquireContainingFrame(ev);
  6299.     if (tempFrame == kODNULL)
  6300.     {
  6301.         _fMenuBar->EnableCommand(ev, kODCommandPageSetup, kODTrue);
  6302.         _fMenuBar->EnableCommand(ev, kODCommandPrint, kODTrue);
  6303.     }
  6304.     else
  6305.     {
  6306.         //_fMenuBar->EnableCommand(ev, kODCommandPageSetup, kODFalse);
  6307.         //_fMenuBar->EnableCommand(ev, kODCommandPrint, kODFalse);
  6308.     }
  6309.  
  6310.     // $$$$$ The rest of these should only be done if we have the menu focus
  6311.     // This test could be avoided by looking at partInfo->fIsActive
  6312.     ODFrame* menuFocus = _fSession->GetArbitrator(ev)->AcquireFocusOwner(ev, _fMenuFocus);
  6313.     if (!frame->IsEqualTo(ev, menuFocus))
  6314.     {
  6315.         ODReleaseObject(ev, menuFocus);
  6316.         return;
  6317.     }
  6318.     else
  6319.         ODReleaseObject(ev, menuFocus);
  6320.     _fMenuBar->EnableCommand(ev, kODCommandViewAsWin, kODFalse); // !frame->IsRoot(ev));
  6321.  
  6322.     // parts bin code stolen from clock.cpp
  6323.     if ( _fPartsBinWin != 0)
  6324.     {
  6325.         ODWindow* window = _fSession->GetWindowState(ev)->AcquireWindow(ev, _fPartsBinWin);
  6326.         if (window) 
  6327.         {
  6328.             _fPartsBinOpen = window->IsActive(ev);
  6329.             ODReleaseObject(ev, window);
  6330.         }
  6331.         else
  6332.             _fPartsBinOpen = kODFalse;        // $$$$$ SHOULD NEVER HAPPEN - BAD!!!!
  6333.     }
  6334.     
  6335. #ifndef NUKE_PARTSBIN_FOR_DR
  6336.     if (_fPartsBinOpen)
  6337.     {
  6338.     // INTL BUG: FOR LOCALISABILITY, READ THE TEXT OUT OF A RESOURCE AND
  6339.     //    USE THE CURRENT SYSTEM SCRIPT AND CURRENT SYSTEM LANGUAGE.
  6340.         menuItem = CreateIText(smRoman, langEnglish, "Hide Parts Bin");
  6341.     }
  6342.     else
  6343.     {
  6344.     // INTL BUG: FOR LOCALISABILITY, READ THE TEXT OUT OF A RESOURCE AND
  6345.     //    USE THE CURRENT SYSTEM SCRIPT AND CURRENT SYSTEM LANGUAGE.
  6346.         menuItem = CreateIText(smRoman, langEnglish, "Show Parts Bin");
  6347.     }
  6348.     _fMenuBar->SetItemString(ev, kODCommandShowPartsBin, menuItem);
  6349.     DisposeIText(menuItem);
  6350.  
  6351.     _fMenuBar->EnableCommand(ev, kODCommandShowPartsBin, kODTrue);
  6352. #endif
  6353.  
  6354.     // PREFERENCES
  6355.     _fMenuBar->EnableCommand(ev,  kODCommandPreferences, kODTrue ) ;
  6356.     // INTL BUG: FOR LOCALISABILITY, READ THE TEXT OUT OF A RESOURCE AND
  6357.     //    USE THE CURRENT SYSTEM SCRIPT AND CURRENT SYSTEM LANGUAGE.
  6358.     menuItem = CreateIText(smRoman, langEnglish, "DrawPart Preferences…");
  6359.     _fMenuBar->SetItemString(ev, kODCommandPreferences, menuItem);
  6360.     DisposeIText(menuItem);
  6361.  
  6362.     // ABOUT
  6363.     _fMenuBar->EnableCommand(ev,  kODCommandAbout, kODTrue ) ;
  6364.     // INTL BUG: FOR LOCALISABILITY, READ THE TEXT OUT OF A RESOURCE AND
  6365.     //    USE THE CURRENT SYSTEM SCRIPT AND CURRENT SYSTEM LANGUAGE.
  6366.     menuItem = CreateIText(smRoman, langEnglish, "About Test Container…");
  6367.     _fMenuBar->SetItemString(ev, kODCommandAbout, menuItem);
  6368.     DisposeIText(menuItem);
  6369.  
  6370.     _fMenuBar->EnableAndCheckCommand(ev, cGray, kODTrue, RGBEqual(pInfo->bgColor,rgbGray));
  6371.     _fMenuBar->EnableAndCheckCommand(ev, cRed, kODTrue, RGBEqual(pInfo->bgColor,rgbRed));
  6372.     _fMenuBar->EnableAndCheckCommand(ev, cGreen, kODTrue, RGBEqual(pInfo->bgColor,rgbGreen));
  6373.     _fMenuBar->EnableAndCheckCommand(ev, cYellow, kODTrue, RGBEqual(pInfo->bgColor,rgbYellow));
  6374.     _fMenuBar->EnableAndCheckCommand(ev, cBlue, kODTrue, RGBEqual(pInfo->bgColor,rgbBlue));
  6375.     _fMenuBar->EnableAndCheckCommand(ev, cMagenta, kODTrue, RGBEqual(pInfo->bgColor,rgbMagenta));
  6376.     _fMenuBar->EnableAndCheckCommand(ev, cCyan, kODTrue, RGBEqual(pInfo->bgColor,rgbCyan));
  6377.     _fMenuBar->EnableAndCheckCommand(ev, cWhite, kODTrue, RGBEqual(pInfo->bgColor,rgbWhite));
  6378.     _fMenuBar->EnableCommand(ev, cOtherColor, kODTrue);
  6379.  
  6380.     // if a part is selected 
  6381.     ODBoolean hasSelection = _fSelection->Count()>0;
  6382.  
  6383.     _fMenuBar->EnableCommand(ev, kODCommandClear, hasSelection); // kODFalse);
  6384.     _fMenuBar->EnableCommand(ev, kODCommandSelectAll, kODFalse); // _fEmbeddedFrames->Count()>0);
  6385.  
  6386.     _fMenuBar->EnableCommand(ev, kODCommandOpen, hasSelection);
  6387.     
  6388.     ODIText* partInfoText;
  6389.     // INTL BUG: FOR LOCALISABILITY, READ THE TEXT OUT OF A RESOURCE AND
  6390.     //    USE THE CURRENT SYSTEM SCRIPT AND CURRENT SYSTEM LANGUAGE.
  6391.     partInfoText = CreateIText(smRoman, langEnglish, "Part Info");
  6392.     _fMenuBar->SetItemString(ev, kODCommandGetPartInfo, partInfoText);
  6393.     DisposeIText(partInfoText);
  6394.     _fMenuBar->EnableCommand(ev, kODCommandGetPartInfo, (!frame->IsRoot(ev) || hasSelection));
  6395.  
  6396.     ODArbitrator* arbitrator = _fSession->GetArbitrator(ev);
  6397.  
  6398.     ODFrame* clipboardFocus = arbitrator->AcquireFocusOwner(ev, _fClipboardFocus);
  6399.     if ( (frame == clipboardFocus) || 
  6400.          (arbitrator->RequestFocus(ev, _fClipboardFocus, frame)) )
  6401.     {
  6402.         _fMenuBar->EnableCommand(ev, kODCommandCut, kODFalse); // hasSelection);
  6403.         _fMenuBar->EnableCommand(ev, kODCommandCopy, kODFalse); // hasSelection);
  6404.         _fMenuBar->EnableCommand(ev, kODCommandPaste, kODFalse); // ValueOnClipboard(ev, _fSession));
  6405.         _fMenuBar->EnableCommand(ev, kODCommandPasteAs, kODFalse);
  6406.     }
  6407.     ODReleaseObject(ev, clipboardFocus);
  6408.     
  6409. #ifdef SCRIPTDEBUG
  6410.     ODIText* scriptMenuText;
  6411.     if (_fScriptingOn) scriptMenuText =  CreateIText(smRoman, langEnglish, "Turn Scripting Off");
  6412.     else scriptMenuText =  CreateIText(smRoman, langEnglish, "Turn Scripting On");
  6413.     _fMenuBar->SetItemString(ev, cToggleScripting, scriptMenuText);
  6414.     DisposeIText(scriptMenuText);
  6415.     _fMenuBar->EnableCommand(ev, cToggleScripting, kODTrue);
  6416. #endif
  6417.  
  6418.     SOM_CATCH_ALL_ENDTRY
  6419. }
  6420.  
  6421. SOM_Scope void  SOMLINK AppleTest_ContainerUndoAction(AppleTest_Container *somSelf, Environment *ev,
  6422.         ODActionData* actionState)
  6423. {
  6424.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  6425.     AppleTest_ContainerMethodDebug("AppleTest_Container","UndoAction");
  6426.  
  6427.     SOM_TRY
  6428.     
  6429.     // FOR NOW, WE JUST HAVE ONE ACTION THAT CAN BE UNDONE OR REDONE.
  6430.     SetBGColorRec*    undoRec = *((SetBGColorRec**)actionState->_buffer);
  6431.     
  6432.     somSelf->SetBGColor2(ev, undoRec->_fFrame, &undoRec->_fOldColor);
  6433.  
  6434.     SOM_CATCH_ALL_ENDTRY
  6435. }
  6436.  
  6437. SOM_Scope void  SOMLINK AppleTest_ContainerRedoAction(AppleTest_Container *somSelf, Environment *ev,
  6438.         ODActionData* actionState)
  6439. {
  6440.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  6441.     AppleTest_ContainerMethodDebug("AppleTest_Container","RedoAction");
  6442.  
  6443.     SOM_TRY
  6444.     
  6445.     // FOR NOW, WE JUST HAVE ONE ACTION THAT CAN BE UNDONE OR REDONE.
  6446.     SetBGColorRec*    undoRec = *((SetBGColorRec**)actionState->_buffer);
  6447.     
  6448.     somSelf->SetBGColor2(ev, undoRec->_fFrame, &undoRec->_fNewColor);
  6449.  
  6450.     SOM_CATCH_ALL_ENDTRY
  6451. }
  6452.  
  6453. SOM_Scope void  SOMLINK AppleTest_ContainerDisposeActionState(AppleTest_Container *somSelf, Environment *ev,
  6454.         ODActionData* actionState,
  6455.         ODDoneState doneState)
  6456. {
  6457.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  6458.     AppleTest_ContainerMethodDebug("AppleTest_Container","DisposeActionState");
  6459.  
  6460.     SOM_TRY
  6461.     
  6462.     ODUnused(doneState);
  6463.     // FOR NOW, WE JUST HAVE ONE ACTION THAT CAN BE UNDONE OR REDONE.
  6464.     delete *((SetBGColorRec**)actionState->_buffer);
  6465.  
  6466.     SOM_CATCH_ALL_ENDTRY
  6467. }
  6468.  
  6469. SOM_Scope void  SOMLINK AppleTest_ContainerWriteActionState(AppleTest_Container *somSelf, Environment *ev,
  6470.         ODActionData* actionState,
  6471.         ODStorageUnitView* storageUnitView)
  6472. {
  6473.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  6474.     AppleTest_ContainerMethodDebug("AppleTest_Container","WriteActionState");
  6475.  
  6476.     SOM_TRY
  6477.     
  6478.     ODUnused(actionState);
  6479.     ODUnused(storageUnitView);
  6480.  
  6481.     SOM_CATCH_ALL_ENDTRY
  6482. }
  6483.  
  6484. SOM_Scope ODActionData  SOMLINK AppleTest_ContainerReadActionState(AppleTest_Container *somSelf, Environment *ev,
  6485.         ODStorageUnitView* storageUnitView)
  6486. {
  6487.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  6488.     AppleTest_ContainerMethodDebug("AppleTest_Container","ReadActionState");
  6489.  
  6490.     ODActionData data;
  6491.     ODUnused(storageUnitView);
  6492.     data._maximum = 0;
  6493.     data._length = 0;
  6494.     data._buffer = kODNULL;
  6495.     return data;
  6496. }
  6497.  
  6498. SOM_Scope void  SOMLINK AppleTest_ContainerInitPart(AppleTest_Container *somSelf, Environment *ev,
  6499.         ODStorageUnit* storageUnit, ODPart* partWrapper)
  6500. {
  6501.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  6502.     AppleTest_ContainerMethodDebug("AppleTest_Container","InitPart");
  6503.  
  6504.     SOM_TRY
  6505.     
  6506.     parent_InitPart(somSelf, ev, storageUnit, partWrapper);
  6507.     
  6508.     _fPartWrapper = partWrapper;
  6509.  
  6510.     somSelf->CommonInitContainerPart(ev);
  6511.     
  6512.     ODStorageUnit* msu = somSelf->GetStorageUnit(ev);
  6513.     ODSUAddPropValue(ev, msu, kODPropContents, kKindTestDraw);
  6514.     _fTestDrawSU = msu->GetDraft(ev)->CreateStorageUnit(ev);
  6515.  
  6516.     ODSUAddPropValue(ev, _fTestDrawSU, kPropScriptingOn, kODBoolean);
  6517.     ODSUAddPropValue(ev, _fTestDrawSU, kODPropDisplayFrames, kODWeakStorageUnitRefs);
  6518.     ODSUAddPropValue(ev, _fTestDrawSU, kODPropFrameGroup, kODULong);
  6519.     ODSUAddPropValue(ev, _fTestDrawSU, kODPropEmbeddedFrames, kODStrongStorageUnitRef);
  6520.     // $$$$$ The type should be something DrawPart specific, not kODStrongStorageUnitRef
  6521.     // since it is storing StorageUnitRefs and xforms in the same stream.
  6522.  
  6523.     SOM_CATCH_ALL_ENDTRY
  6524. }
  6525.  
  6526. SOM_Scope void  SOMLINK AppleTest_ContainerInitPartFromStorage(AppleTest_Container *somSelf, Environment *ev,
  6527.         ODStorageUnit* storageUnit, ODPart* partWrapper)
  6528. {
  6529.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  6530.     AppleTest_ContainerMethodDebug("AppleTest_Container","InitPartFromStorage");
  6531.  
  6532.     SOM_TRY
  6533.     
  6534.     parent_InitPartFromStorage(somSelf, ev, storageUnit, partWrapper);
  6535.     
  6536.     _fPartWrapper = partWrapper;
  6537.     
  6538.     somSelf->CommonInitContainerPart(ev);
  6539.  
  6540.     ODStorageUnit* su;
  6541.      ODStorageUnitRef aSURef;
  6542.     ODShape* newShape;
  6543.     ODULong offset, offsetLimit;
  6544.     ODRgnHandle newRegion;
  6545.     Point xform;
  6546.  
  6547. ODUnused(newRegion);
  6548.  
  6549.     su = somSelf->GetStorageUnit(ev);
  6550.     
  6551.     _fTestDrawSU = su->GetDraft(ev)->AcquireStorageUnit(ev, 
  6552.                     ODGetStrongSURefProp(ev, su, kODPropContents, kKindTestDraw));
  6553.                     
  6554.     su = _fTestDrawSU;
  6555.  
  6556.     _fScriptingOn = ODGetBooleanProp(ev, su, kPropScriptingOn, kODBoolean);
  6557.     
  6558.      su->Focus(ev, kODPropDisplayFrames, kODPosSame, 0, 1, kODPosFirstSib);
  6559.     offsetLimit = su->GetSize(ev);
  6560.     for (offset = 0; offset < offsetLimit; offset += sizeof(ODStorageUnitRef))
  6561.     {
  6562.         su->SetOffset(ev, offset);
  6563.         StorageUnitGetValue(su, ev, sizeof(ODStorageUnitRef), (ODValue)&aSURef);
  6564.         
  6565.         if (su->IsValidStorageUnitRef(ev, aSURef)) {        
  6566.             ODFrame* frame =
  6567.                 su->GetDraft(ev)->AcquireFrame(ev, su->GetIDFromStorageUnitRef(ev, aSURef));
  6568.             _fDisplayFrames->AddLast((ElementType)frame);
  6569.             frame->SetDroppable(ev, kODTrue);
  6570.         }
  6571.     }
  6572.  
  6573.     _fFrameGroupIDCounter = ODGetULongProp(ev, su, kODPropFrameGroup, kODULong);
  6574.  
  6575.      su->Focus(ev, kODPropEmbeddedFrames,kODPosSame,0,1,kODPosFirstSib); 
  6576.     offsetLimit = su->GetSize(ev);
  6577.     newShape = kODNULL;
  6578.     for (offset = 0; offset < offsetLimit;)
  6579.     {
  6580.         su->SetOffset(ev, offset);
  6581.         StorageUnitGetValue(su, ev, sizeof(ODStorageUnitRef), (ODValue)&aSURef);
  6582.         offset += sizeof(ODStorageUnitRef);
  6583.         ODFrame* frame =
  6584.             su->GetDraft(ev)->AcquireFrame(ev, su->GetIDFromStorageUnitRef(ev, aSURef)); // TÇ: frame is consumed below.
  6585.         _fEmbeddedFrames->AddLast((ElementType)(ODFrame*)frame);
  6586.  
  6587.         su->SetOffset(ev, offset);
  6588.         StorageUnitGetValue(su, ev, sizeof(ODPlatformTransform), (ODValue)&xform);
  6589.         offset += sizeof(Point);
  6590.         
  6591.         ODTransform* transform = 
  6592.             frame->CreateTransform(ev)->SetQDOffset(ev, &xform); // DMc SetQDOffset() returns this. TÇ: transform is consumed below.
  6593.         
  6594.         ODShape* frameShape = frame->AcquireFrameShape(ev, kODNULL);
  6595.         if( newShape )
  6596.             newShape->CopyFrom(ev, frameShape);
  6597.         else
  6598.             newShape = frameShape->Copy(ev);
  6599.             
  6600.         // TÇ: $$$$$ Should really be using CreateFrameProxy.
  6601.         frameShape->Release(ev); frameShape = kODNULL;
  6602.         newShape->Transform(ev, transform);
  6603.         RgnHandle newRegion = newShape->CopyQDRegion(ev);
  6604.         _fContents->AddLast((ElementType)(new Proxy(newRegion, (ODFrame*)frame, transform))); //  TÇ: transform is consumed here.
  6605.     }
  6606.     if (newShape) newShape->Release(ev); newShape = kODNULL;
  6607.  
  6608.     // Remove any temporary properties that may have been cloned in during data interchange
  6609.     ODSURemoveProperty(ev, su, kODPropContentFrame);
  6610.     ODSURemoveProperty(ev, su, kODPropExternalTransform);
  6611.     ODSURemoveProperty(ev, su, kODPropSuggestedFrameShape);
  6612.     ODSURemoveProperty(ev, su, kODPropMouseDownOffset);
  6613.     ODSURemoveProperty(ev, su, kPropFrameInfo);
  6614.  
  6615.     SOM_CATCH_ALL_ENDTRY
  6616. }
  6617.  
  6618. // ••• ValueOnClipboard •••
  6619.  
  6620. ODBoolean ValueOnClipboard(Environment* ev, ODSession* session)
  6621. {
  6622.     ODBoolean        result = kODFalse;
  6623.     ODClipboard*    clipboard = session->GetClipboard(ev);
  6624.  
  6625.     TRY
  6626.         ODStorageUnit* su = clipboard->GetContentStorageUnit(ev);
  6627.         result =  su->Exists(ev, kODPropContents, kODNULL, 0);
  6628.     CATCH_ALL
  6629.     ENDTRY
  6630.  
  6631.     return result;
  6632. }
  6633.  
  6634. //------------------------------------------------------------------------------
  6635. // DrawPart::HasExtension
  6636. //------------------------------------------------------------------------------
  6637.  
  6638. SOM_Scope ODBoolean     SOMLINK AppleTest_ContainerHasExtension(AppleTest_Container *somSelf, Environment *ev,
  6639.         ODType extensionName)
  6640. {
  6641.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  6642.     AppleTest_ContainerMethodDebug("AppleTest_Container","HasExtension");
  6643.     
  6644.     SOM_TRY
  6645.     
  6646. #ifdef SCRIPTDEBUG
  6647.     if (!_fScriptingOn) return kODFalse;
  6648. #endif
  6649.  
  6650. #ifndef SCRIPTING_OFF
  6651.     if (!ODISOStrCompare((ODISOStr)extensionName, kODExtSemanticInterface))
  6652.         return kODTrue;
  6653.     else
  6654. #endif
  6655.         return kODFalse;
  6656.  
  6657.     SOM_CATCH_ALL_ENDTRY
  6658.     return kODFalse;
  6659. }
  6660.  
  6661.  
  6662. //------------------------------------------------------------------------------
  6663. // DrawPart::AcquireExtension
  6664. //------------------------------------------------------------------------------
  6665.  
  6666. SOM_Scope ODExtension*     SOMLINK AppleTest_ContainerAcquireExtension(AppleTest_Container *somSelf, Environment *ev,
  6667.         ODType extensionName)
  6668. {
  6669.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  6670.     AppleTest_ContainerMethodDebug("AppleTest_Container","AcquireExtension");
  6671.  
  6672.     SOM_TRY
  6673.     
  6674. #ifndef SCRIPTING_OFF
  6675.     if (!ODISOStrCompare((ODISOStr)extensionName, kODExtSemanticInterface))
  6676.     {
  6677.         _fSemtIntf->Acquire(ev);
  6678.         return _fSemtIntf;
  6679.     }
  6680.     else
  6681. #endif
  6682.         return kODNULL;
  6683.  
  6684.     SOM_CATCH_ALL_ENDTRY
  6685.     return kODNULL;
  6686. }
  6687.  
  6688. //------------------------------------------------------------------------------
  6689. // DrawPart::ReleaseExtension
  6690. //------------------------------------------------------------------------------
  6691.  
  6692. SOM_Scope void     SOMLINK AppleTest_ContainerReleaseExtension(AppleTest_Container *somSelf, Environment *ev,
  6693.         ODExtension* extension)
  6694. {
  6695.     AppleTest_ContainerData *somThis = AppleTest_ContainerGetData(somSelf);
  6696.     AppleTest_ContainerMethodDebug("AppleTest_Container","ReleaseExtension");
  6697.  
  6698.     SOM_TRY
  6699.     
  6700. #ifndef SCRIPTING_OFF
  6701.     if( extension == _fSemtIntf )
  6702.         _fSemtIntf = kODNULL;
  6703.     delete extension;
  6704. #endif
  6705.  
  6706.     SOM_CATCH_ALL_ENDTRY
  6707. }
  6708.  
  6709.  
  6710. //------------------------------------------------------------------------------
  6711. // AboutDialogFilter
  6712. //------------------------------------------------------------------------------
  6713.  
  6714. pascal Boolean AboutDialogFilter(DialogPtr dialog,
  6715.                               EventRecord* event,
  6716.                               short* itemHit)
  6717. {
  6718.     ODBoolean handled = kODFalse;
  6719.     
  6720.     Environment* ev = somGetGlobalEnvironment();
  6721.     
  6722.     if (event->what == nullEvent)
  6723.     {
  6724.         gSession->GetDispatcher(ev)->Dispatch(ev, (ODEventData*)event);
  6725.     }
  6726.     else if (event->what == updateEvt &&
  6727.                 (WindowPtr) event->message != dialog)        
  6728.     {
  6729.         gSession->GetDispatcher(ev)->Dispatch(ev, (ODEventData*)event);
  6730.     }
  6731.     else if (event->what == activateEvt &&
  6732.                 (WindowPtr) event->message != dialog)        
  6733.     {
  6734.         gSession->GetDispatcher(ev)->Dispatch(ev, (ODEventData*)event);
  6735.     }
  6736.     else if (event->what == mouseDown) 
  6737.     {
  6738.         handled = kODFalse;
  6739.     }
  6740.     else if (event->what == mouseUp) 
  6741.     {
  6742.         handled = kODTrue;
  6743.         *itemHit = 1;
  6744.     }
  6745.     else if ((event->what == keyDown) || (event->what == autoKey))
  6746.     {
  6747.         handled = kODTrue;
  6748.     }
  6749.  
  6750.     return handled;
  6751. }
  6752.  
  6753. void ShowMyDragHilite(Environment* ev, ODDragAndDrop* dad, ODFacet* facet)
  6754. {
  6755.     if (facet != kODNULL) {
  6756.         ODULong attributes = dad->GetDragAttributes(ev);
  6757.         if ((!(attributes & kODDragIsInSourceFrame)) && (gDragHilitedFacet != facet)) {
  6758.         
  6759.             CommonInvertFacet(ev, dad, facet, true);
  6760.             gDragHilitedFacet = facet;
  6761.         }
  6762.     }
  6763. }
  6764.  
  6765. void HideMyDragHilite(Environment* ev, ODDragAndDrop* dad, ODFacet* facet)
  6766. {
  6767.     if (gDragHilitedFacet == facet) {
  6768.         CommonInvertFacet(ev, dad, facet, false);
  6769.         gDragHilitedFacet = kODNULL;
  6770.     }
  6771. }
  6772.  
  6773. void CommonInvertFacet(Environment* ev, ODDragAndDrop* dad, ODFacet* facet, ODBoolean show)
  6774. {
  6775.     CFocus prepareForRendering(ev, facet);
  6776.     ODFrame*    displayFrame = facet->GetFrame(ev);
  6777.     TempODShape frameShape = displayFrame->AcquireFrameShape(ev, kODNULL); // DMc refcount - make temp
  6778.     RgnHandle    bRgn = frameShape->GetQDRegion(ev);
  6779.  
  6780. #ifndef UseMyDragHilite    
  6781.     RgnHandle destRgn = NewRgn();
  6782.     CopyRgn(bRgn, destRgn);
  6783.     InsetRgn(destRgn, 3, 3);
  6784.     XorRgn(bRgn, destRgn, destRgn);
  6785.     InvertRgn(destRgn);
  6786.     ODDisposeHandle((Handle)destRgn);
  6787.     
  6788. #else
  6789.  
  6790.     if (show)
  6791.         ShowDragHilite(dad->GetDragReference(ev), bRgn, true);
  6792.     else
  6793.         HideDragHilite(dad->GetDragReference(ev));
  6794.  
  6795. #endif
  6796. }
  6797.  
  6798. #undef VARIABLE_MACROS
  6799.